Skip to main content
November 8, 2014
Answered

Applying Different Function to one Button based on which Frame it is

  • November 8, 2014
  • 1 reply
  • 397 views

Hi,

I am working on this Presentation where i have Next and Back Button

In Normal conditions , Net button would only take the user to the  Next Frame, but in Some Frames , i have certain Popups which has to be loaded before user can move out of that frame.

I am trying to develop that logic to work around same Mouse Event Listener but different function applied when needed.

I am very new to AS3 so any guidance in this matter would be highly appreciated in making this code work.

This topic has been closed for replies.
Correct answer Ned Murphy

You could put a conditional or switch in the event handler function that takes action based on the currentFrame property.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
November 8, 2014

You could put a conditional or switch in the event handler function that takes action based on the currentFrame property.

November 8, 2014

Ned. thats what i am trying to put but for some reasons , its not taking me passed that frame , i have succeeded to stop it on a certain frame by removing the vent Listener but once i am done with the condition , it should reactive the Listener , but thats not happening , i know its a pretty simple thing , but due to my lack of experience with AS3 , its causing me trouble to troubleshoot it all by my self.

Here is my Code:

btn_nxt.addEventListener(MouseEvent.CLICK, simplenext);

////////////////////////////////SIMPLENEXT FUNCTION FOR NEXT BUTTON ///////////////////////////////////////////

function simplenext(event: MouseEvent): void
{

if (currentFrame == 9)
{
btn_nxt.removeEventListener(MouseEvent.CLICK, simplenext);
trace("Normal Next Button Disabled");
btn_nxt.addEventListener(MouseEvent.CLICK, nextframe9);
trace("Frame 9 Next Button Activated");
btn_notice1.addEventListener(MouseEvent.CLICK, loadnotice1);
pop1.closebtn.addEventListener(MouseEvent.CLICK, unloadbtn1);
}

else {

nextFrame();

}
}

/////////////////////////FUNCTION FOR FRAME 9 //////////////////////////////////////

Please note that Count is the Counter variable that i defined to increment once the popup movie clip is loaded

function nextframe9(event: MouseEvent): void

  {

  if(count == 1 && stage.contains(pop1) )

  {

  removeChild(pop1);

  }

  if(count == 1)

  {

  nextFrame();

  }

  else

  {

  addChild(pop1);

  pop1.x = 40;

  pop1.y = 120;

  count = 1;

  }

  }

Ned Murphy
Legend
November 8, 2014

What I suggested is not what I see you implementing.  You are trying to change the function that the button calls and you don't need to do that, but you can if you work out the logic properly.  Chances are you are missing following the logic if it is not behaving as you intend.  I think you are tangling yourself in the logic by separating things out as you are.

This is where you need to learn how to make the best use of the trace() function.  If you expect something to happen based on conditions being met, then you need to check those conditions to see if they are what you think rthey should be.