Jimmy
Jimmy

Reputation: 3

how to save event Listeners

I'm trying to use shared object but i don't know how do i save event listeners (e.g. if a mouse event has already removed before saving). Let's say that "onThis" function removes a mouse event

    function onThis(event:MouseEvent):void
    {
    levAll.theLev.gotoAndStop(2);
    boxAll.levHit.removeEventListener(MouseEvent.CLICK, onLevHit);
     }
    //save function
    function onSaveBtn(event:MouseEvent):void
        {
    sharedObject.data.levData = levAll.theLev.currentFrame;
    // save that boxAll.levHit mouse event removed
        }
    //load function
    function onLoadBtn(event:MouseEvent):void
        {
     levAll.theLev.gotoAndStop(sharedObject.data.levData);
    // load that boxAll.levHit mouse event removed
       } 

Upvotes: 0

Views: 1383

Answers (2)

user45623
user45623

Reputation: 621

You shouldn't ever need to "save" your event listeners for some buttons in a shared object in the way that you are describing; you must be approaching this from the wrong angle.

It's hard to say what you should be doing instead, since you haven't really explained what you're trying to accomplish and your variable names and function names aren't meaningful. However, in general, what you want to do is save the state of the object that the button interacts with, and add or remove the event listener based on that state.

function onThis(event:MouseEvent):void
{
    levAll.theLev.gotoAndStop(2);
    boxAll.levHit.removeEventListener(MouseEvent.CLICK, onLevHit);
    boxAll.levHit.wasClicked = true;
 }

function onSaveBtn(event:MouseEvent):void
{
    sharedObject.data.levData = levAll.theLev.currentFrame;
    sharedObject.data.clickedLevHit = boxAll.levHit.wasClicked;
}

function onLoadBtn(event:MouseEvent):void
{
    hiton = sharedObject.data.hitData;
    if (!sharedObject.data.clickedLevHit) {
        boxAll.levHit.addEventListener(MouseEvent.CLICK, onLevHit);
    }
}

Upvotes: 0

Amir Rasti
Amir Rasti

Reputation: 768

I'm not sure that I understand it completely but maybe

var EventExists:Boolean ;
EventExists=boxAll.hasEventListener(MouseEvent.CLICK);

sharedObject.data.levData = EventExists;

Upvotes: 1

Related Questions