开发者

Call variable inside a function AS3.0

I'm trying to pass a variable through a function, but I'm getting it's value 0

Here's my code:

thumbLoader.addEventListener(MouseEvent.CLICK, goToCategory);

function goToCategory(e:MouseEvent) {
    trace(c);
    gotoAndStop(2);
    doSMTH(0);
}

this trace gives me value of 0.

Normally I would do goToCategory(c) and inside that category I would get it's value, but in this case I'm calling this function with an event, how can that be do开发者_高级运维ne?

var c is declared globally, so I'm using it above this code in different place...

is there smth like global $c like in PHP.. or there's some other way to do it?

Thanks in advance!!!


You could try to not use globals, but if you really don't know how, then one solution is to use a static class, and add your globals to it:

package {

    public class Globals {

        static public var c:String = "";

    }

}

Then access the global with:

trace(Global::c);

Just writing this code makes me shiver but that's one way to have globals.


I assume variable c is available where you are adding mouse click listener. In that case, this should do what you want.

thumbLoader.addEventListener(MouseEvent.CLICK, function(e:MouseEvent)
                                               {
                                                   goToCategory(c);
                                               }
);

function goToCategory(c:*)
{
    trace(c);
    gotoAndStop(2);
    doSMTH(0);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜