You have to cast the root property because it's statically typed as a
DisplayObject. Because the player/API doesn't know what document class
you might use for your root object, it types root as the base class
your document class must inherit from.

Looking at your code, it seems that you're trying to develop AS3 as if
it were AS2. In general, manually traversing the display list using
parent or root properties is a sign of bad design. In this case,
you're tying your program architecture to your display list
architecture -- if you move one thing in your FLA, everything will

Instead, build your classes in a more object-oriented manner. I don't
know what class the snippet you posted is in, but it looks like all
you need is property derived from another display object's width. In
this case, consider adding a property called "maxWidth" or something
similar to the object's constructor, and pass the value in when you
create the object. That way you don't need to traverse the display
list to find the information you need -- everything is nice and


On 2/19/08, Johan Nyberg <[EMAIL PROTECTED]> wrote:
> Hi, I have a question regarding referencing objects on the stage from
> other objects. You should be able to use the root from any object that
> has been added to the display list using addChild. But when I do so I
> get this error message:
> 1119: Access of possibly undefined property loader through a reference
> with static type flash.display:DisplayObject.
> The only way for me to do what I want is if I cast the root reference
> to the class of my document class. For example, if the name of my
> document class is MyDocumentClass it would be like this:
> MyDocumentClass( root ).theObjectIWantToAccess.someProperty
> My questions are:
> 1. Why do I have to cast the root property?
> 2. Is this the best way to go around what I want to do.
> To illustrate what I'm talking about, here's a snippet of code:
> if( this.inputBubble.x + this.inputBubble.width >
> PokerHandComp(root).frame_mc.width )
>   {
>         this.inputBubble.x = x;
>         this.inputBubble.bubble_mc.scaleX = -1;
>         this.inputBubble.txt.x = - this.inputBubble.bubble_mc.width + 20;
> }
> In this case my document class is called PokerHandComp.
> Regards,
> Johan Nyberg
> Designer and web developer
> 08 - 50 00 24 30
> 070 - 407 83 00
> _______________________________________________
> Flashcoders mailing list

Cory Petosky : Lead Developer : PUNY
1618 Central Ave NE Suite 130
Minneapolis, MN 55413
Office: 612.216.3924
Mobile: 240.422.9652
Fax: 612.605.9216
Flashcoders mailing list

Reply via email to