How to pass variables into inline functions in Action Script 2

前端 未结 2 995
长情又很酷
长情又很酷 2021-01-22 19:46

I have the following function, but I can\'t seem to get the myVar variable into the inline function. What am I doing wrong here? What I would like to have happen is when I cli

2条回答
  •  借酒劲吻你
    2021-01-22 20:18

    This is a scope issue - when you apply an onRelease function like this in as2, the scope of the function is the MovieClip you apply the function to, not the calling function.

    Because you are using AS2 and MovieClip is dynamic, you can assign the variable to the MC directly:

    function doSomething():Void
    {   
        myMc.myVar = "hello computer";
    
        myMc.onRelease = function(){
            trace(this.myVar);
        }
    }
    

提交回复
热议问题