Skip to main content
Known Participant
June 21, 2008
Answered

movie clip access tip request.

  • June 21, 2008
  • 4 replies
  • 718 views
I am attempting to access a movieclip on the stage by its instance name.
It is not a child of anything but the stage.

I can do this in the document class via:
var mc:MovieClip = pumpkin_mc;
trace (mc);

but, if I try the same in a non-document class, it cannot find the movieclip.

why? and How do I?


I could access it with:
var _mc:MovieClip = MovieClip(e.currentTarget.root).pumpkin_mc;

but I am writing a function that effects the pumpkin only, and I want to access the pumpkin_mc in that class without feeding the function the pumpkin instance object.

i.e.
openPumpkin()

closePumpkin()


This topic has been closed for replies.
Correct answer kglad
Ok, gotcha so far.

I am attempting to set a global static variable or constant to the pumpkin instance so other functions in the same package can utilize that variable or constant.


for all variables and objects that you want to be globally available, you can create a class with a static object.

then because objects are dynamic, you can assign any property you want to the object:

4 replies

kglad
Community Expert
Community Expert
June 22, 2008
you're welcome.
Known Participant
June 22, 2008
BAM! I get it.

Thank you.
Known Participant
June 22, 2008
No difference they are the same thing. The pumpkin instance object is named pumpkin_mc.

To specify further. The action I am attempting will not be connected to the pumpkin_mc with any event.

Example: If click a button, call openPumpkin()
"pumpkin_mc is not the button object"

looking something like this:


public function openPumpkin(){
var mc:MovieClip = pumpkin_mc;

... do stuff to pumpkin_mc;
pumpkin_mc.x = 20;
etc...

}

kglad
Community Expert
Community Expert
June 22, 2008
in oop, properties and methods (like openPumpkin() ) are encapsulated. ie, they are not accessible outside the class.

so, you can no more call openPumpkin() without having access to a class member, than you can use call the draw() method of the bitmapdata class without a bitmapdata instance.

you can use static properties or methods. then anything that can access the class itself (as opposed to a class member), can call that static function:

Known Participant
June 22, 2008
Ok, gotcha so far.

I am attempting to set a global static variable or constant to the pumpkin instance so other functions in the same package can utilize that variable or constant.

kglad
Community Expert
Community Expert
June 22, 2008
what's the difference between pumpkin_mc and "..the pumpkin instance object"?