restoring events with array

2 views
Skip to first unread message

Don Booth

unread,
Jun 17, 2010, 7:11:26 PM6/17/10
to EventController, donb...@rogers.com
I'm sure I'm doing this incorrectly.

Maybe an example will do it?

I've added some controllers:


EC.add(this, MouseEvent.ROLL_OVER, overHandler, false, 0, true,
"thumbListener");
EC.add(this,MouseEvent.ROLL_OUT, outHandler,false, 0,true,
"ThumbListener");
EC.add(this,MouseEvent.CLICK, clickHandler, false, 0, true,
"ThumbListener");

Then I removed this:
EC.remove("ThumbListener");

But since I will want to restore them I put them in an array. The
array has class scope.
_eventArray = EC.remove("ThumbListener");

Okay, now I want to restore these listeners.

EC.addGroup(_eventArray); <== this does not work.
EC.addGroup([eventArray}); <== this does not work.

I studied addGroup in the documentation but, as far as I can tell, it
only deals with removing listeners, though it looks as though the same
thing should work to add them.

Much thanks for your assistance,


Don Booth,
Toronto



Ben Fhala

unread,
Jun 22, 2010, 12:56:14 PM6/22/10
to eventco...@googlegroups.com, donb...@rogers.com
Sorry for the delay,
no worries at all.

here is a sample of how it works attached. look how i setup the enterframe events. and how i'm using the array "a" to add the events and remove them.
the real logic is these few lines:
//HERE WE ARE SETTING UP THE ENTER FRAME EVENTS :
var a:Array = [];
    function onSetupEnterframes(evt:MouseEvent):void{
        EC.addGroup(a);
    }
   
   
    //this rem shows how to remove a cluster.
    function onClearEnterframes(evt:MouseEvent):void{
        a = EC.remove(PROJECT_UID+"enterFrame");
    }


I have a global variable a and I'm putting the results into the addGroup or garbing them from the remove function.
 

here is the full code (but you can grab that from the fla as well and see it in action:


/**
 * VERSION: 1.3
 * AS3
 * UPDATES AND DOCUMENTATION AT: http://fla.as/ec
 * ...
 * @author Ben Fhala with support by Core team.
 * @site http://fla.as/ec
 * @date 03/08/2010
 * Copyright (c) 2009-2010 Everything Nice Inc.
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 **/


import _as.fla.events.EC; //download library source from : http://fla.as/

//project ID for clustering
const PROJECT_UID:String="sample_";

var sprContainer:Sprite = addChild(new Sprite()) as Sprite; //container for movieclips
var mcButtons:MovieClip;


startup();

function startup() { //creating 100 movieclips and starting up the events reset method
    for(var i:int=0;i<100;i++)    createElement();
    addChild(mcButtons);
    addControlEvents();
    for (i=0; i<sprContainer.numChildren; i++)
            EC.add(sprContainer.getChildAt(i),Event.ENTER_FRAME,onChildEnterFrame, PROJECT_UID+"enterFrame");
}

function onChildEnterFrame(evt:Event):void{
    evt.target.x+=5-Math.random()*10 ;
    evt.target.y+=5-Math.random()*10;
   
}

function createElement():void{
    var spr:Sprite = new Sprite();
    spr.graphics.beginFill(int(Math.random()*0xffffff)); //random color
    spr.graphics.drawCircle(0,0,Math.random()*5);
    spr.graphics.endFill();
    spr.x = Math.random()*stage.stageWidth;
    spr.y = Math.random()*stage.stageHeight;
    spr.buttonMode = true;
    sprContainer.addChild(spr);
}


function addControlEvents(evt:*=null):void{
    EC.add(mcButtons.cbEnterFrameAdd,MouseEvent.CLICK,onSetupEnterframes,PROJECT_UID+"controlls");
    EC.add(mcButtons.cbEnterFrameRem,MouseEvent.CLICK,onClearEnterframes,PROJECT_UID+"controlls");
       
}



//HERE WE ARE SETTING UP THE ENTER FRAME EVENTS :
var a:Array = [];
    function onSetupEnterframes(evt:MouseEvent):void{
        EC.addGroup(a);
    }
   
   
    //this rem shows how to remove a cluster.
    function onClearEnterframes(evt:MouseEvent):void{
        a = EC.remove(PROJECT_UID+"enterFrame");
    }




   





--
Best regards,

Ben Fhala
http://local.anxpl.com

Phone #: +1.347.409.4499
eFax # : +1.973.807.5903
Israel #: 03.970.8777
test.fla
Reply all
Reply to author
Forward
0 new messages