开发者

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 out开发者_JAVA百科side the function. How shall I reffer to the movieclip that events is called from?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜