Processing
 

How can I give flash stage instances unique properties in Flash Professional to pass to AS3 script?

25/05/2012 10:13#1

justinl

Member

Joined at: 10 months ago

Post: 6

Thank: 0

Thanked: 0

I've started building a rough game engine framework in Flash Professional and I'm curious how I can create objects in the Flash library that I'm able to drag onto the stage and assign properties that are accessible from AS3.

Example:
I want to create a switch object (e.g. a light switch), so that when the player interactes with it, it triggers something specific in code such as a light in the room turns on.

I understand that Flash has built in UI components that you can define properties within the Flash Professional environment (see image below), and I'm wondering if there's a way to create my own custom style components so that I can essentially have my level file open in flash (.fla) and then drag a switch component from my library, and type in some information such as what light it is controlling, and any other information I want.

How can I give flash stage instances unique properties in Flash Professional to pass to AS3 script?

(above is an example of the type of parameter control I'm looking for)

I've read a bit about extending the flash UIComponent class but I feel that that's not the right approach because it's overkill for what I want. All I want is to pass some basic parameters from a library stage instance into AS3. I do not want to pass data via the instance name because this seems very messy if I want to have more complex interaction.

Thanks!

16/06/2012 14:05Top#2

Joined at: 10 months ago

Post: 113

Thank: 0

Thanked: 0

I thik what people are trying to say is that you can have the whole thing be data driven, and so you can combine the IDE with the data to come up with your final game.

But consider this...it might be what you want.

If you have, for instance, a BaseSwitch Class:

public Class BaseSwitch extends MovieClip {    private var _lightName:String;    private var _light:Light;    public function get lightName():String {       return lightName;    }    pubic function set lightName(value:String):void {       if (value != _lightName) {         _lightnName = value;         //Note I don't advocate having children reach into their parents like this,         //but you sound like you don't want the parent involved in the process, so         //this is one way you could do it.         if (parent.hasOwnProperty(lightName) && parent[lightName] is Light) {            _light = parent[lightName];         } else {            trace('Could not find light', _lightName);         }        }    }    //other code to listen for gestures and operate the light } 

Now, when you want a switch to operate a specific light name, create a library instance and set its base class to BaseSwitch. When you close the dialog where you set the base Class, you'll notice that it gives you a dialogue that it couldn't find the Class in the Class path and one will be generated. You're going to replace it with a Class that sets the lightName. Create a new AS3 Class in the root directory with the same name as your library instance. It should look something like this:

public class SpecificSwitch {    public function SpecificSwitch() {       super();       lightName = 'theSwitch';    } } 

Other possible choices involve having the parent Class match up instances of switch with instances of light based on name, so if it finds a light1 and a light1Switch, it either gives a reference to the light to the switch or it simply sets up a mapping in its own event listening system.

14/04/2014 23:19Top#3

Joined at: 6 months ago

Post: 1

Thank: 0

Thanked: 0

I would create a "switch" movie clip and export it to actionscrip, same with a "light" movie clip. The in the main class .as file I would inset them into the stage, using addChild (clips) and then add a click listener to the "switch" movie clip to control the "light".

02/05/2016 18:27Top#4

Joined at: 6 months ago

Post: 1

Thank: 0

Thanked: 0

This can be easily done.

Component(s) are wrong approach in my opinion.

Firstly you would want to setup Actionscript linkage / label your Library item. In Library Panel. - Right Click on "yourMC" >> click "Properties". - In Properties dialog Tick "Export for Action Script" - Then Name your Class eg "yourMC_Class"

now MC is ready to be referenced in your code.

next you would want to Dynamically add your "yourMC" from library to stage. which can be done like such.

// first reference library item

var yourMC_ref:yourMC_Class = new yourMC_Class(); 

// Then load dynamic mc item into var

var your_MC_OBJ = yourMC_ref; 

// then add your MC to stage.

this.addChild(your_MC_OBJ); your_MC_OBJ.x = 200; your_MC_OBJ.y = 100; 

in a nutshell that's how I add library items to stage.

Obviously thats the basic function / code.

In a project I would have all code in an external class, in which case you would just set vars as public vars

public var yourMC_ref:yourMC_Class = new yourMC_Class(); public var your_MC_OBJ = yourMC_ref; 

and the last 3 lines of code into a public function

public function ADD_First_MC() {        this.addChild(your_MC_OBJ);        your_MC_OBJ.x = 200;        your_MC_OBJ.y = 100; } 

Now 'your_MC_OBJ' can be used in more complex ways.

eg. to create a light switch there are many options depending on how you need to approch functionality. eg. Apply a different MC library item to "your_MC_OBJ" play specific frame within MCs.

However If it was me I would just use mouse function to switch light on or off using addChild removeChild. eg.

public var LightON = 0; public var yourMC_ref:yourMC_Class = new yourMC_Class(); public var your_MC_OBJ = yourMC_ref; 

then create a public function that handles on / off events

public function LightON_OFF()      {          if(LightON == 1)             {                this.addChild(your_MC_OBJ);                your_MC_OBJ.x = 200;                your_MC_OBJ.y = 100;             }          if(LightON == 0)             {                this.removeChild(your_MC_OBJ);             }      } 

Hope this helps.

12/05/2016 15:35Top#5

Joined at: 6 months ago

Post: 1

Thank: 0

Thanked: 0

So, for what you want, while it may not be the best way to do what you want, I understand it's your experience you are constructing.

Use components, yes...in the following way (the most simple one):

  • Create a Movie Clip
  • Right-click it in library
  • Click on "Component Definitions"
  • Add a property, set a name, a variable name (var test, for this matter) and a default value
  • Click OK

  • Open your movie clip

  • Open code for the first frame and declare the variable without an initial value (var test:String;)
  • Trace it's value ( trace( test ); )

  • Go back to the stage root

  • Drag and drop the item from library to stage
  • Test it (Cmd/Ctrl + Enter) (maybe it will print null, dunno why, it ignores the default value sometimes)

  • Select your component on stage

  • Open the properties panel (Windows > Properties)
  • Go to Component Parameters on this panel and change the property value

  • You should see the value traced on console

And, I think, like this you can use properties from components for what you want, like using a String and getting the controlled mc by its name.

Good luck

Similar articles

Open a folder in finder/explorer from a webpage?

5 years ago - Reply: 2 - Views: 80

How do I escape a reserved word in Actionscript?

5 years ago - Reply: 2 - Views: 198

Save PPS/PPT files as SWF using C#

5 years ago - Reply: 2 - Views: 171

Ways of making a graphic/visual novel in flash

6 years ago - Reply: 3 - Views: 114

Use PhoneGap + HTML5 and an Embedded Flash Movie

5 years ago - Reply: 2 - Views: 96

View word docs and PDF in browser?

5 years ago - Reply: 2 - Views: 52

ActionScript 3 Read JPEG quality

7 years ago - Reply: 2 - Views: 59

Export/Test Movie Issues

5 years ago - Reply: 3 - Views: 39

Flash always on top in Android browser workaround?

5 years ago - Reply: 2 - Views: 149

Sending Json Form from Flash AS3

5 years ago - Reply: 2 - Views: 29

parsing a swf/fla (using php?)

6 years ago - Reply: 2 - Views: 44

Getting high FPS on Flash/AIR games for mobile?

4 years ago - Reply: 2 - Views: 58

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re