开发者

Flex 3: is it possible to add an event listender to a boolean variable?

I have a boolean variable, projectsLoaded that is set to false when my application loads. As i'm sure you can imagine, when the final project module loads, I set the variable to be true. Is there开发者_运维技巧 a way I can trigger a series of functions to run once that variable is set to true?


You can use setters and getters to execute code when value changes. Just be sure to use the setter instead of setting the private variable value.

EDIT : I just saw you tagged your question with addeventlistener. I edited the code to use that instead.

private _projectsLoaded:Boolean = false;

//this could be done elsewhere, that's just an example
private function init():void
{
     addEventListener("projectsLoaded", onProjectsLoaded);
}

public function get projectsLoader():Boolean
{
    return _projectsLoaded;
}

public function set projectsLoaded(value:Boolean):void
{
    if(_projectsLoaded!=value)
    {
        _projectsLoaded = value;
        if(value)
            dispatchEvent(new Event("projectsLoaded"));
    }
}

protected function onProjectsLoaded(event:Event):void
{
    //your logic here
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜