i'm pretty confused over the following issue and would be grateful for some clarity.
generally, how i work involves designing all of my graphics in Flash Authoring, converting them to Sprite symbols by changing the base class to flash.display.Sprite, give my instances names and finally export them to ActionScript.
the approach actually permits me to dynamically create properties in code on my Sprite instances that i've exported to ActionScript, just as if they were instances of MovieClips. i'm not entirely sure why i'm able to do this, but i can. in polling the objects to make sure of their superclass, they are indeed Sprites and not MovieClips.
however, as expected, if i program a new sprite from scratch in code and try to dynamically add a property to the new programmed sprite a compile time error will result.
package
{
import flash.display.Sprite;
import flash.utils.getQualifiedSuperclassName;
public class Document extends Sprite
{
public function Document()
{
trace(getQualifiedSuperclassName(blueOvalInstance));
//flash.display::Sprite (it's not a MovieClip)
trace(blueOvalInstance.hasOwnProperty("currentFrame"));
//false (ok, ok, it's definately not a MovieClip)
blueOvalInstance.myNewProperty = true;
//dynamically added boolean property on a Sprite instance
trace(blueOvalInstance.hasOwnProperty("myNewProperty"));
//true. fancy that! my Flash Authoring exported Sprite has a dynamically added property
codeSprite();
}
private function codeSprite():void
{
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 boolean property on a Sprite instance, just like before!
//Compile Time Error!!!
//1119: Access of possibly undefined property anotherNewProperty through a reference with static type flash.display:Sprite.
}
}
}
so why is it that can i dynamically add properties to exported sprites in my document class if they are not MovieClips, while i can not if i create them myself in code?
the following image shows a new BlueOval symbol being exported to ActionScript from Flash Authoring with the base class of Sprite (not MovieClip). notice the new green (instead of blue) colored "Movie Clip" icon in the library panel.