Skip to main content
Known Participant
January 7, 2013
Answered

onclick next button change the marker Tween:Tween position

  • January 7, 2013
  • 1 reply
  • 1286 views

I have a file which is having some buttons at the bottom like and two buttons at the left and right sides called "next_btn" nad "prev_btn" also a tween which is folowing the buttons at the bottom when they are being clicked. The action is folowing below.

My problem is i want to change the tween position when i am clicking on the "next_btn" and Prev_btn" suppose if the tween arrow is on the "button 3" currently the moment i am clicking on the next_btn the tween arrow should go the "button 4" accordingly if i click on the rev button it should go to the "button 2".

Here is the sample which i am trying to do http://www.franklincovey.com/tc/

Basically i want to say that i want to make this banner and i have reached till this stage after this i am not being able to do further, need your valuable support.

I would request you to download this flash file which is containing everything

Download - http://www.touchpixl.com/files.zip

Here is the code that i am using

Layer 1 - Frame 1

next_slide.addEventListener(MouseEvent.MOUSE_UP,buttonPressed);

prev_slide.addEventListener(MouseEvent.MOUSE_UP,buttonClicked);

function buttonPressed(event:MouseEvent){

 

     if(holder.currentFrame == 1)

     {

          holder.nextFrame();

                      trace("Clicked 1");

     }

     else if(holder.currentFrame == 2)

     {

          holder.nextFrame();

                      trace("Clicked 2");

     }

     else if(holder.currentFrame == 3)

     {

          holder.nextFrame();

                      trace("Clicked 3");

     }

     else if(holder.currentFrame == 4)

     {

          holder.nextFrame();

                      trace("Clicked 4");

     }

     else if(holder.currentFrame == 5)

     {

          holder.nextFrame();

                      trace("Clicked 5");

     }

     else if(holder.currentFrame == 6)

     {

          holder.gotoAndStop(1);

                      trace("Clicked 6");

     }

}

function buttonClicked(event:MouseEvent){

 

     if(holder.currentFrame == 1)

     {

          holder.gotoAndStop(6);

                      trace("Clicked 1");

     }

     else if(holder.currentFrame == 2)

     {

          holder.prevFrame();

                      trace("Clicked 2");

     }

     else if(holder.currentFrame == 3)

     {

          holder.prevFrame();

                      trace("Clicked 3");

     }

     else if(holder.currentFrame == 4)

     {

          holder.prevFrame();

                      trace("Clicked 4");

     }

     else if(holder.currentFrame == 5)

     {

          holder.prevFrame();

                      trace("Clicked 5");

     }

     else if(holder.currentFrame == 6)

     {

          holder.prevFrame();

                      trace("Clicked 6");

     }

}

Layer 2 - Frme 1

import fl.transitions.Tween;

import fl.transitions.easing.*;

var curMarkerXPos:Number = btn1.x;

var duration:Number = 1.5;

function markerFollow (event:MouseEvent):void {

          var markerTween:Tween = new Tween(marker, "x", Strong.easeOut, curMarkerXPos, event.target.x, duration, true);

          curMarkerXPos = event.target.x;

}

btn1.addEventListener(MouseEvent.CLICK, markerFollow);

btn2.addEventListener(MouseEvent.CLICK, markerFollow);

btn3.addEventListener(MouseEvent.CLICK, markerFollow);

btn4.addEventListener(MouseEvent.CLICK, markerFollow);

btn5.addEventListener(MouseEvent.CLICK, markerFollow);

btn6.addEventListener(MouseEvent.CLICK, markerFollow);

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

One way to make this work is to store your button "x" positions, or the buttons themselves, in an array and use a counter to keep track of which button your arrow is currently over.  When you click next you advance the counter and tween the arrow to the next array x value.  The same goes for the reverse.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
January 7, 2013

One way to make this work is to store your button "x" positions, or the buttons themselves, in an array and use a counter to keep track of which button your arrow is currently over.  When you click next you advance the counter and tween the arrow to the next array x value.  The same goes for the reverse.

Known Participant
January 7, 2013

Sir i could not do that, can i request you to do that for me? here is the latest file i have used below

Layer - 2 - this is for next and prev buttons

next_slide.addEventListener(MouseEvent.MOUSE_UP,buttonPressed);

prev_slide.addEventListener(MouseEvent.MOUSE_UP,buttonClicked);

function buttonPressed(event:MouseEvent){

 

     if(holder.currentFrame == 1)

     {

          holder.nextFrame();

                      trace("Clicked 1");

     }

     else if(holder.currentFrame == 2)

     {

          holder.nextFrame();

                      trace("Clicked 2");

     }

     else if(holder.currentFrame == 3)

     {

          holder.nextFrame();

                      trace("Clicked 3");

     }

     else if(holder.currentFrame == 4)

     {

          holder.nextFrame();

                      trace("Clicked 4");

     }

     else if(holder.currentFrame == 5)

     {

          holder.nextFrame();

                      trace("Clicked 5");

     }

     else if(holder.currentFrame == 6)

     {

          holder.gotoAndStop(1);

                      trace("Clicked 6");

     }

}

function buttonClicked(event:MouseEvent){

 

     if(holder.currentFrame == 1)

     {

          holder.gotoAndStop(6);

                      trace("Clicked 1");

     }

     else if(holder.currentFrame == 2)

     {

          holder.prevFrame();

                      trace("Clicked 2");

     }

     else if(holder.currentFrame == 3)

     {

          holder.prevFrame();

                      trace("Clicked 3");

     }

     else if(holder.currentFrame == 4)

     {

          holder.prevFrame();

                      trace("Clicked 4");

     }

     else if(holder.currentFrame == 5)

     {

          holder.prevFrame();

                      trace("Clicked 5");

     }

     else if(holder.currentFrame == 6)

     {

          holder.prevFrame();

                      trace("Clicked 6");

     }

}

Layer - 3 - this is for the tween

/*

Script Written By Adam Khoury @ www.developphp.com

Code line insight and explanations are in the video

*/

import fl.transitions.Tween;

import fl.transitions.easing.*;

var curMarkerXPos:Number = btn1.x;

var duration:Number = 1.5;

function markerFollow (event:MouseEvent):void {

 

          var markerTween:Tween = new Tween(marker, "x", Strong.easeOut, curMarkerXPos, event.target.x, duration, true);

          curMarkerXPos = event.target.x;

 

}

function setupEvents() {

          // associate events with event handlers

          next_slide.addEventListener(MouseEvent.CLICK, clickButtonHandler);

}

setupEvents();

function clickButtonHandler(e:MouseEvent) {

          //trace("Clicked Button!");

           trace("Tween");

}

btn1.addEventListener(MouseEvent.CLICK, markerFollow);

btn2.addEventListener(MouseEvent.CLICK, markerFollow);

btn3.addEventListener(MouseEvent.CLICK, markerFollow);

btn4.addEventListener(MouseEvent.CLICK, markerFollow);

btn5.addEventListener(MouseEvent.CLICK, markerFollow);

btn6.addEventListener(MouseEvent.CLICK, markerFollow);

Sir i would request you to just see this link where you can see how far i have been able to make this possible and where exactly i am stuck.

link - http://touchpixl.com/upload/

Thank you

Ned Murphy
Legend
January 7, 2013

Few people will chance downloading files in these forums, and just as many will do the work for you.  Your code shows no attempt to do this so how can you say you you could not.  What aspect of what I described are you unable to understand/do?  Can you place the objects in an array?  Can you declare a counter variable?  Can you determine the location of an object?  Can you tween an object?  Or is all the code you show something you found somewhere and you have no idea how it works?