How can I save the value from "event.currentTarget"

hi
I have 4 buttons and each one of them contain a rollover,rollout and a Cick event.
When I click in one button I need to remove the  rollout and rollover eventlistener for the present button and when I click another button I need to add it back the  the rollover and rollout eventlistener to the button that was click before, and for the new button I need to remove the rollout and rollover and so on...

I think if you see my code you will understand better  ,
Thanks

ps: I am using AS3
var Xpos:Number = 198;
var Ypos:Number = 15;
var swf:MovieClip;
var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest("swfs/Page1.swf");

loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Btns Universal function

function btnClick(event:MouseEvent):void {
	
	loader.unloadAndStop();	
	removeChild(loader);		
	var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.currentTarget.name + ".swf");
	event.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
	event.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);	
	//How can I add back the eventlistener for the button that I remove it
	//sample1.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
	//sample1.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
	loader.load(newSWFRequest);
	loader.x = Xpos;
    loader.y = Ypos;
	addChild(loader);
}
// Btn listeners
sample1.addEventListener(MouseEvent.CLICK, btnClick);
sample1.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
sample1.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
function onRollOverHandlerPlay(event:MouseEvent):void{
	sample1.gotoAndPlay("over");	
}
function onRollOutHandlerPlay(event:MouseEvent):void{
	sample1.gotoAndPlay("out");	
}


Page1.addEventListener(MouseEvent.CLICK, btnClick);
Page1.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay1);
Page1.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay1);
function onRollOverHandlerPlay1(event:MouseEvent):void{
	Page1.gotoAndPlay("over");	
}
function onRollOutHandlerPlay1(event:MouseEvent):void{
	Page1.gotoAndPlay("out");	
}

sample2.addEventListener(MouseEvent.CLICK, btnClick);
sample2.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay2);
sample2.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay2);
function onRollOverHandlerPlay2(event:MouseEvent):void{
	sample2.gotoAndPlay("over");	
}
function onRollOutHandlerPlay2(event:MouseEvent):void{
	sample2.gotoAndPlay("out");	
}


sample3.addEventListener(MouseEvent.CLICK, btnClick);
sample3.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay3);
sample3.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay3);
function onRollOverHandlerPlay3(event:MouseEvent):void{
	sample3.gotoAndPlay("over");	
}
function onRollOutHandlerPlay3(event:MouseEvent):void{
	sample3.gotoAndPlay("out");	
}

Open in new window

LVL 4
eddyperuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gingermolemanCommented:
Hi,

is it fair to say then that only 1 button at a time will be without its roll over and roll out?
If ive understood you correctly then its (sort of):

var prevButton:Object;
var firstClick = 0;


function btnClick(event:MouseEvent):void {
      
      loader.unloadAndStop();      
      removeChild(loader);      
      var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.currentTarget.name + ".swf");

              //Ive added the listeners back to the prev button clicked as we set the value of the present clicked button last
if (firstClick == 0){
//this condition is only true once
firstClick = 1;
}else{
      prevButton.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
      prevButton.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
}
      event.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
      event.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);      
      //now we capture this button click ready for the next cycle
                prevButton = event.currentTarget;
      loader.load(newSWFRequest);
      loader.x = Xpos;
                loader.y = Ypos;
      addChild(loader);
}


GMM
0
dgofmanCommented:
It's hard to understand what you want, but looks like this one

var Xpos:Number = 198;
var Ypos:Number = 15;
var swf:MovieClip;
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest("swfs/Page1.swf");;
//loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Btns Universal function

function btnClick(event:MouseEvent):void {
	var clip:MovieClip = event.currentTarget as MovieClip;
	clip.removeEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
	clip.removeEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);	

	function enabledEvents(e:Event):void{
		clip.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
		clip.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
	}
	loader.unloadAndStop();	

	var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.currentTarget.name + ".swf");
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, enabledEvents); 
	loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, enabledEvents);
	loader.load(newSWFRequest);
}

function onRollOverHandlerPlay(event:MouseEvent):void{
	event.currentTarget.gotoAndPlay("over");
	trace("HERE")
}
function onRollOutHandlerPlay(event:MouseEvent):void{
	event.currentTarget.gotoAndPlay("out");	
}

function addEvents(clip:MovieClip):void{
	clip.addEventListener(MouseEvent.CLICK, btnClick);
	clip.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
	clip.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
}

addEvents(sample1);
addEvents(sample2);
addEvents(sample3);
//addEvents(Page1);

Open in new window


0
eddyperuAuthor Commented:
The ideas is what "gingermoleman:" said :
   Only 1 button at a time will be without its roll over and roll out.

dgofman:  It doesn't work; I can see that the removeevenlistener is working but  this line add the listener back, before I click another button.
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, enabledEvents);

gingermoleman : It didn't work, not errors in the output but it didn't work. :(

ps: By the way I forgot to mention that onload the player will start playing Page1.swf so that means the button page1 at the begging should be in the stage "On" without rollover and rollout; sorry about this I really forgot .
Thank you so much for all your help!!! thank you thank you!!!

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

gingermolemanCommented:
Hi,

ok, think I see what the problem is. See the attached file, when you do a mouse over or out it gets traced out. Click on btn1 try rolling in and out, no more traces. Now click btn2 and try again.  btn1 now back btn2 removed. Its a bit raggedy but you should be able to pull this into your work easily enough.

GMM
1btnOnly.fla
0
eddyperuAuthor Commented:
Sweet!!! Awesome gingermoleman...it works, but I still need to have the page1, as the default "ON" without  rollover and rollout.
Any ideas, I am giving you my code to check it out

Thanks
var Xpos:Number = 198;
var Ypos:Number = 15;
var swf:MovieClip;
var clip:MovieClip;
var loader:Loader = new Loader();

var firstClick = 0;
var defaultSWF:URLRequest = new URLRequest("swfs/Page1.swf");
loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Btns Universal function
function btnClick(event:MouseEvent):void
{
	loader.unloadAndStop();
	removeChild(loader);
	var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.currentTarget.name + ".swf");
	if (firstClick == 0)
	{
		//this condition is only true once
		firstClick = 1;		
	}
	else
	{		
		clip.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
		clip.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
		clip.gotoAndPlay("out");		
	}
	event.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
	event.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
	//now we capture this button click ready for the next cycle;
	clip = event.currentTarget as MovieClip;
	loader.load(newSWFRequest);
	loader.x = Xpos;
	loader.y = Ypos;
	addChild(loader);
}
//----------------------------------------------------------------------------------------------------
// function for Rollover and Rollout
function onRollOverHandlerPlay(event:MouseEvent):void
{event.currentTarget.gotoAndPlay("over");}

function onRollOutHandlerPlay(event:MouseEvent):void
{event.currentTarget.gotoAndPlay("out");}
//----------------------------------------------------------------------------------------------------
// Btn listeners
Page1.addEventListener(MouseEvent.CLICK, btnClick);
Page1.buttonMode = true;
Page1.useHandCursor = true;
Page1.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
Page1.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);

Life.addEventListener(MouseEvent.CLICK, btnClick);
Life.buttonMode = true;
Life.useHandCursor = true;
Life.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
Life.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);

ShortTermDisability.addEventListener(MouseEvent.CLICK, btnClick);
ShortTermDisability.buttonMode = true;
ShortTermDisability.useHandCursor = true;
ShortTermDisability.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
ShortTermDisability.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);

LongTermDisability.addEventListener(MouseEvent.CLICK, btnClick);
LongTermDisability.buttonMode = true;
LongTermDisability.useHandCursor = true;
LongTermDisability.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
LongTermDisability.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);

Accident.addEventListener(MouseEvent.CLICK, btnClick);
Accident.buttonMode = true;
Accident.useHandCursor = true;
Accident.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
Accident.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);

CriticalIllness.addEventListener(MouseEvent.CLICK, btnClick);
CriticalIllness.buttonMode = true;
CriticalIllness.useHandCursor = true;
CriticalIllness.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
CriticalIllness.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);

IndividualShortTermDisability.addEventListener(MouseEvent.CLICK, btnClick);
IndividualShortTermDisability.buttonMode = true;
IndividualShortTermDisability.useHandCursor = true;
IndividualShortTermDisability.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
IndividualShortTermDisability.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);

Open in new window

0
dgofmanCommented:
Hi eddyperu,
All code what I am submitting I always testing on my local machine.
I know my code is working and you will get back your events when SWF finished loading or get HTTP error.
Please attach your come example of your "swfs/" + event.currentTarget.name + ".swf files
0
gingermolemanCommented:
Hi,

Do you mean that when the swf 1st starts you want btn1 to NOT have the rollover and rollout? If so, just don't add them in the 1st place! Change var tempObj:Object; to
Var tempObj:Object = btn1;
As you are now presetting the previous button as btn1 at start, we don't need to bother with the if to check for the 1st click. Make sense?

Gmm
0
gingermolemanCommented:
sorry, actually LOOKING at your code! Should be

var clip:MovieClip = Page1;



function btnClick(event:MouseEvent):void
{
      loader.unloadAndStop();
      removeChild(loader);
      var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.currentTarget.name + ".swf");
//DONT need the IF statement at all now, as on first click event clip = Page1 and isnt null
            clip.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
            clip.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
            clip.gotoAndPlay("out");            
      
      event.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
      event.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);
      //now we capture this button click ready for the next cycle;
      clip = event.currentTarget as MovieClip;
      loader.load(newSWFRequest);
      loader.x = Xpos;
      loader.y = Ypos;
      addChild(loader);
}


delete these lines as the first click anywhere will add em in

Page1.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandlerPlay);
Page1.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandlerPlay);


0
eddyperuAuthor Commented:
gingermoleman: that didn't work :(
0
gingermolemanCommented:
Hi,

Ive updated my example to not have listeners on btn 1 at the start. Does this show you the way?

Gmm
1btnOnly.fla
0
eddyperuAuthor Commented:
gingermoleman: that only will work when any of the buttons have been Click but what about at the start of the movie.

Thanks
0
gingermolemanCommented:
Check it again. In the 2nd copy the event listeners for btn1 are commented out.  Out tempObj is now being set as if btn1 has already been clicked. If you run this you will see no activity on btn1 but on all others. Click on any other btn and btn1 now has rollover and out.

Gmm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.