Danielle
Danielle

Reputation: 53

Referencing an array on stage from another movieclip

I have an array of MovieClips (on the main stages actions) that i want to refer to from within other movieclips placed on the stage.

var hotSpots:Array =[hotSpot1, hotSpot2, control_mc, tip_mc]

for each (var removeHotspots:MovieClip in hotSpots)
{
    removeHotspots.visible = false;
}

How do i refer back to this array from within another movieclip without having to add the array again?

I tried...

var hotSpots:Array = Object(this).hotSpots

and then within my event Listener...

for each (var removeHotspots:MovieClip in hotSpots)
    {
        removeHotspots.visible = true;
    }

But it doesn't seem to work? Can anyone help. I have alot of arrays like this that i really dont want to have to add to each movieclip everytime i need to call them.

Upvotes: 0

Views: 251

Answers (1)

mackanward
mackanward

Reputation: 66

"this" refers to the MovieClip your code is within. If you want to access the parent MovieClip (in this case the root or stage) you can either use parent.hotSpots or stage.hotSpots. However, this requires the MovieClip to be added to the stage (and thereby the display list), otherwise both parent and stage will be null.

If you want to wait for a MovieClip to be on stage before executing code where you refer to the stage variable you can use the event Event.ADDED_TO_STAGE

Upvotes: 1

Related Questions