How Flash works with classes associated with your MovieClips
Let's say you create a movieclip, you plan on affecting said movieclip with actions in you scripts, so during the creation process you click the "Advanced" button and export it for actionscript. Flash, being the helpful guy that it is (I snickered as I wrote that) looks for a class in your source path that matches the class name you just entered for the movieclip (this actually is very helpful). Say I draw a robot on the stage, convert it to movieclip, and call it "Robot". If a class with the name Robot isn't found then Flash will create a dynamic one at run time, but if there is one, Flash is smart enough to put two and two together and apply all actions in that class to the Robot movieclip, including the actions applied to the named movieclips nested inside of Robot. Not so when you are using Flash assets in Flex Builder.Flex and swcs
You can have access to you assests created in Flash while working in Flex, Just tick the box in publish settings. It'll export a swc. A swc is basically a compression format of sorts, Flash bundels a swf and an xml file together in one package, the xml file holds a reference to everything that has been "Exported for Actionscipt" in your movie. Let's say we're developing in the Flex environment, it allows you to do something like this:public var robot:Robot = new Robot();
Now let's say that we had other named movieclips nested inside of our Robot movieclip, let's say we have a Head movieclip named head as long as we have declared the type of our movieclip as Robot we can do this:
robot.head.x = 120;
Pretty awesome! I can draw and layout my robot in flash, name all the nested movieclips and refer to them in flex, they'll have all the same properties and methods as any other movieclip! But all is not so keen. Let's say nested inside head we have an Eye movieclip named eye. We can't refer to that by doing this:
robot.head.eye.x = 120;
Flex won't know what the hell you are talking about. This isn't a huge deal when your drawing robots. You can just nest all of the robot bits in Robot but when you're making interface elements sometimes you want to nest things. Let's say you are making a simple photo viewer have a standard button that you are using in a few different places in the app. It has a label that you dynamically add text to. Now let's say that you want to make a pop up panel, you'd like to use the same button, you could place it with actionscript but wouldn't it be so much nicer to lay it out in the Flash authoring environment? It sure would, but you can't do this:
var panel:Panel = new Panel();
panel.button.buttonLabel.text = "close"
The Handy Tip Buried in this Long Explanation
buttonLable is nested inside of button which is nested inside of panel. When faced with this, I would always place the button in my actionscript and be done with it, no big deal.today I figured out a work around. You can do this:
var panel:Panel = new Panel();
var panelButton:MyButton = panel.button;
and now you can do this:
panelButton.buttonLabel.text = "close";
Awesome!!
No comments:
Post a Comment