Sebi
Sebi

Reputation: 1436

Problem with referece to object

I have object in which I have rectangle on one layer and following code on another layer:

import flash.events.Event;
this.myMouseMove = function( e:Event ) {
    if(Object(this).currentFrame == 1) {
        Object(this).play();
    }
}
this.overlay.addEventListener(MouseEvent.MOUSE_MOVE,this.myMouseMove);

And Object(this).play() or checking for current frame doesn't work, nor tracing a value define outside the function. How shall I reffer to the movieclip that events is called from?

Upvotes: 0

Views: 72

Answers (2)

Patrick
Patrick

Reputation: 15717

Use the currentTarget property of the event :

myMouseMove = function( e:Event ):void {
    // here i suppose that your overlay object is a MovieClip
    var mc:MovieClip=MovieClip(e.currentTarget)
    if(mc.currentFrame == 1) {
        mc.play();
    }
}

N.B. Whenever it's possible use strong typing and not Object casting

Upvotes: 1

mway
mway

Reputation: 4392

Have you tried MovieClip() instead of Object()? It's more appropriate when you expect the (potentially coerced) object to act like a MovieClip.

Also, you may not be working on the object you intend. You need to specify the object at hand.

Try changing it to something like this:

import flash.events.Event;
myObjectName.myMouseMove = function(e:Event):void {
    if(myObjectName.currentFrame == 1)
        myObjectName.play();
};

where myObjectName is the instance name of the object containing the rectangle.

Upvotes: 0

Related Questions