开发者

JSFL - reading metadata onDocumentChanged

I am building a flash panel that reads metadata from a .fla when it is active in the Flash IDE. This pane开发者_如何学Gol is also storing metadata in the .fla and that is no problem. What is problematic is that I do not know how to stop the event listener from listening for onDocumentChange.

I want it to listen for it as long as it is open, but when it's closed it should clean up after itself because trying to read metadata every time a new document is selected is not a very nice thing to do.

I have tried to listen for all kind of events in the panel to detect when the user closes it, but with no success.

Anyone knows anything about this?


I've done a lot of work with Events in JSFL, and the sad truth is that the system is flawed. Document events are fine, but layer and frame events are very unreliable; executing in the wrong order, layer events not firing when you come out of an edit, etc, etc.

Polling from the panel is often the best way to do it, and is not such a performance hit.

Document events however, are OK. The documentation on how to remove them is incorrect, see Dru Kepple's post here on what you should do:

http://summitprojectsflashblog.wordpress.com/2010/11/08/jsfl-get-fl-removeeventlistener-to-work/


Hmm, if you can store metadata in the .fla (or have some sort of unique ID anyway) you could check in the event listener if the document with that is still open somehow?

So basically fingerprint the .fla and before doing any work in the listener check for the existence to see if the file is open. If not, remove the listener, if yes, fire away the normal event handling.


Within your listener function include another function which loops through all swf panels in the IDE, checking if the name of your panel exists. If it doesn't then remove your listener and return out of your listener function.

function myListenerFunction () {
    if ( !checkForPanel( myPanelName ) ) {
        fl.removeEventListener( type, eventID );
        return;
    }
}

function checkForPanel( arg_panelName ) {

    var target_panelName = arg_panelName;   
    var target_panelsArr = fl.swfPanels;

    var i;
    var iLen = target_panelsArr.length;
    var _swfPanel;
    for ( i = 0; i < iLen; i++ ) {

        _swfPanel = target_panelsArr[i];

        if ( (_swfPanel.name) == target_panelName ) {
            return true;
        }       
    }

    return false;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜