PDA

View Full Version : Accessing parent properties / casting



kitsunegari
April 27th, 2008, 05:14 AM
Hi

I have a problem with accessing the properties of a parent movieclip in AS3

I have 2 movieclips on my scene: clip1 and clip2

I have some actionscript inside clip2 that I would like to use to access some properties of clip1

So I tried this code:
trace((this.parent.parent as MovieClip).clip1.y);but I get the following error:
Access of possibly undefined property some through a reference with static type flash.display:DisplayObjectContainer.

It seems to me the path I use to get the properties of clip1 is correct, isn't it?

Thanks in advance for your help

Felixz
April 27th, 2008, 09:27 AM
trace(Object(this.parent).parent.clip1.y);

kitsunegari
April 27th, 2008, 03:13 PM
It doesn't seem to work either


Please see the attached file to get the flash project (very simple flash file with 2 clips)

Thanks in advance for your help

Felixz
April 27th, 2008, 05:11 PM
delete first trace and replace second with this
trace(Object(this.parent).clip1.y);
It gets 77

kitsunegari
April 27th, 2008, 05:19 PM
thanks it works :)

For all the future readers, the following line works too

trace(parent.getChildByName("clip1").y);