PDA

View Full Version : Accessing properties through 'root'.



TastyLamp
June 1st, 2007, 09:44 AM
Within a class that represents 'slide.panel', and is added to the display list, I have code that tries to access a public variable I set in the document class, like so:


root.satellites.push(sat);

'satellites' is the public variable, of course.

Flash throws the error; 1119: Access of possibly undefined property satellites through a reference with static type flash.display:DisplayObject.

I got around this problem by making the public variables static and using 'Main.satellites' (Main being the document class) instead of 'root.satellites' - but I would still like to know what I am doing wrong, if anything? Thanks for any help.

Nikini
June 1st, 2007, 10:01 AM
did you try using stage?

TastyLamp
June 1st, 2007, 10:06 AM
did you try using stage?

Yes, stage does not work either.

mathew.er
June 1st, 2007, 10:20 AM
Its a compile error, right?

then

root['satellites'].push(sat); or if you use a document class, you can use
WhateverTheDocumentClassIsCalled ( root ).satellites.push(sat);

senocular
June 1st, 2007, 11:12 AM
MovieClip(root) will also work

http://www.kirupa.com/forum/showthread.php?p=2120340#post2120340

TastyLamp
June 1st, 2007, 11:17 AM
MovieClip(root) will also work

http://www.kirupa.com/forum/showthread.php?p=2120340#post2120340

Ahhhh. Thanks for that. It all makes sense now. :azn: