flash - ActionScript - Dynamically Adding Property to Sprite -


I am very confused about the following issue and would be grateful for some clarity.

Generally, how do I work, all my graphics are included in the design of flash authoring, they are converted to flash class flash to convert to symbols of Sprite. Display , Name my instances and finally export them to Action Script.

The approach really allows me to dynamically create properties in the code on my sprite examples for animation, like they were examples of MovieClips, I'm not sure why I can do this I am, but I can. In making sure to vote for their Super Class objects, they are actually Sprites and do not have movie clips.

However, as expected, if I program a new phant from scratch in the code and dynamically try to add a property, the new programmed sprite will be the result of a compile time error.

  package {import flash.display.Sprite; Import flash.utils.getQualifiedSuperclassName; Public class document spreads (public work documents) (trace (getquualifiedSuperclassName (Blue Oval Instance)); //flash.display :: Sasvitt (this is not a movie clip) trace (BlueOvlineStation. HasOwnProperty ("currentFrame")) ; // Wrong (okay, okay, this is definitely not a movie clip) blueOvalInstance.myNewProperty = true; // dynamically adds a blue property to a Sprite instance trace (BlueOvienstance. HasOwnProperty ("myNewProperty")) True; // true My Flash authoring has been exported in the SPRATT Dynamically added property code HCITIT ();} Personal Function codeSprite (): Zero {var myCodedSprite: Sprite = new Sprite (); myCodedSprite.graphics.beginFill (0xFF0000); MyCodedSprite .graphics.drawRect (0, 0, 100, 100); myCodedSprite.graphics.endFill (); addChild (myCodedSprite); MyCodedSprite.anotherNewProperty = true; // Dynamically added a Boolean property to a sprite example; Like! // Compile Time Error !!! // 1119: Static Type Flash With a Reference With Probably Undefined Using a new property of the leaf: Sprite. }}}  

So why is it that I can dynamically add sprites exported to my document class if they are not MovieClips, then I can not do them if I code them Make in

The following image shows that flash authoring is being exported from a new blue oval symbol action script based on Sprite (not a movie clip). Notice the new green (instead of the blue color) "Movie Clip" icon in the Library panel.

alt text

To add properties, you must define a class as a dynamic class during runtime.

Check out this page:


Comments