Bindlestick
Bindlestick

Reputation: 63

Access MovieClip within a MovieClip

I have a MovieClip called Tile, which has its own class. I have the below code in a for loop, which creates a grid.

var tile:MovieClip = new Tile();
tile.gotoAndStop(Floor1[i][u]+1);
tile.x = ((u-i)*tileh)+365;
tile.y = ((u+i)*tileh/2)+70;
addChild(tile);

tile.addEventListener(MouseEvent.ROLL_OVER, mouseover);

Now, there's another moveiclip in Tile called Outline. It is not a class. What I want to do is to have the Outline movieclip go to a frame when I roll over the tile variable with my mouse.

Below is the function for the mouse event. I have tried event.currentTarget.Outline.gotoAndStop(3) but it doesn't seem to work. I get a reference error #1069: Property Outline not found on Tile and there is no default value.

function mouseover(event:MouseEvent)
        {
            event.currentTarget.Outline.gotoAndStop(3);
        }

Upvotes: 0

Views: 70

Answers (1)

Josh
Josh

Reputation: 8159

Is Outline (all variables should be lower case, camel case by the way. Capital implies it is a class name) a public variable? You should declare Outline in global scope as follows:

package com.blah.blah
{
    public class Tile extends DisplayObjectContainer {

        public var outline:DisplayObject;

        public function Tile() {
            // instantiate outline here
        }
    }
}

Basic explanation of access modifiers:

  • Public: Can be accessed from any class
  • Private: Can be accessed from only the class it is declared in
  • Internal: Can be accessed only by classes in the same package
  • Static: Only one instance exists, can only be accessed through class scope (Class.function())
  • Protected: Only classes that extend that class can access that object
  • Final: Children cannot override the function

Upvotes: 1

Related Questions