Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

Animated line showing route from one button to the next in flash 8

I am creating an interactive map with hot spots of 10 locations, I would like to create an animated line that would join up the dots from previous hotspot (button) clicked to current button clicked. This would show the path from one location to the next. How would I go about coding this using action script - can this be done using the drawing API in flash8 ?

Any information or pointers would be great.

Thanks
0
surfjoe
Asked:
surfjoe
  • 2
1 Solution
 
Ramy_atefCommented:
Hi
here is an tutorial that will do what you want:)

The Drawing API

http://www.kirupa.com/developer/actionscript/tricks/drawing_api.htm

Regards,
Ramy
0
 
trigger-happyCommented:
It should be possible but I can only give a rough idea on how it would be done since I myself haven't touched the drawing API (but i know what it can do from reading tutorials and stuff). Basically you'd have some sort of global object that would keep track of the last button clicked (particularly the location). When the next button is clicked, you'd have a call to the global object to check if a previous button was clicked and if so, draw a line from 1 point to the other. Another thing I would suggest is to store the line MCs in an array so that you can delete them later on when needed (like when you implement a "clear lines" button).

What you'll be needing is a class (let's call it LineController) that would have functions which the buttons on stage would call.
class LineController{
       private var prevx:Number;
       private var prevy:Number;
       private var newx:Number;
       private var newy:Number;
       private var prevclick:Boolean; //used to determine if there was a click before
       private var lineArray:Array; //container for all our lines
       private var lineCounter:Number; //used for counting how many lines we have

       function LineController(){
              prevclick = false;
              lineArray = new Array();
              lineCounter = 0;
       }

       function btnClicked(int x, int y):Void{
              if(!prevclick){
                     prevx = x;
                     prevy = y;
                     prevclick = true;
              }else{
                     newx = x;
                     newy = y;
                     DrawLine();
              }
       }

       function DrawLine():Void{
              //using the coordinates stored, we draw the line from prev points to new points then add the movieclip to the array

              //increment the lineCounter
              lineCounter++
              //this one is for assuming you want a connect the dots function instead of connect 2 dots only
              prevx = newx;
              prevy = newy;
       }

       function ClearLines():Void{
              for(var i = 0; i<lineArray.length; i++){
                     lineArray[i].unloadMovie();
              }
       }
}

1st fram of your _root timeline, you'd have something like this:
_global.lcontrol = new LineControl();

Then your buttons would have this:
on(release){
       _global.lcontrol.btnClicked(this._x, this._y);
}

You'll just have to fill in the drawing part since I'm not that familiar with it ^-^; Chances are that you'll also have to be careful with the array since I have a feeling that it could get buggy...

--trigger-happy
0
 
furmigaCommented:
Okie surfjoe let's make a simple point to point


supose u have 2

but1
but2

Supose the start point begins from but1

on the frame

var startpoint_x = but1._x + (but1._height/2)
var startpoint_y = but1._y + (but1._width/2)

now, on the button make a event

on(release)
{
      this.createEmptyMovieClip ("new_line", 1)
      with (new_line)
      {
               lineStyle (1, 0xFFFFFF, 50); // define the line
            moveTo (startpoint_x,startpoint_y); // put the start of the line at the position
            lineTo ( but2._x + (but2._height/2), but2._y + (but2._width/2)); // draw the line
      }
}
0
 
furmigaCommented:
Now, to join points supose u have 4 buttons:

but1
but2
but3
but4

I dont know how you going to do with the start location but You can add a option so the user can choose from where he is going to start.

in the frame

var startpoint : Number = 1; // If the user don't choose a start point it will be the first button.
var nextpoint  : Number = 1; // used to set the all points
var positions : Array = new Array(); // Array to manage all positions
var count : Number = 1; // number of lines to create (accordind to the number of points)

// populate the array with  X and Y values from each button (CENTER POSITION)
// this is a multi array --- array with arrays ---
// the positions[1] refers to the but1
// the positions[1][0] refers to the center X of the but1
// the positions[1][1] refers to the center Y of the but1

positions[1]= [but1._x + (but1._height/2),but1._y + (but1._width/2)];
positions[2]= [but2._x + (but2._height/2),but2._y + (but2._width/2)];
positions[3]= [but3._x + (but3._height/2),but3._y + (but3._width/2)];
positions[4]= [but4._x + (but4._height/2),but4._y + (but4._width/2)];

function jumpto(final:Number) // this make things happen
{
      // delete previous lines
      for (i=1;i<5;i++)
      {
            eval("new_line"+i).clear();
      }
      // Lets see if the button clicked is not the start point "duhh" :)
      if (final <> startpoint)
      {
            count = 1 // sets the count to 1 for next usage
            nextpoint = startpoint // let the startpoint alone :)
            while (final <> nextpoint)
            {
                  this.createEmptyMovieClip ("new_line"+count, count) // this creates an empty MC
                  with (eval("new_line"+count)) // this calls the MC created
                  {
                           lineStyle (1, 0xFFFFFF, 50);  // set the line degin
                        // put the "pencil" over the start position
                        moveTo (positions[nextpoint][0],positions[nextpoint][1]);
                        // now lets see if the line goes to the begining or to the end of our buttons sequence
                        if (final > nextpoint)
                        {
                              nextpoint+=1
                        }
                        else
                        {
                              nextpoint-=1
                        }
                        // Draw the line
                        lineTo (positions[nextpoint][0],positions[nextpoint][1])
                  }
                  count++ //incress the count
            }
      }
}


in each button just add

jumpto(X) // where X is the number of the button

ie. button4

on(release)
{
      jumpto(4)// this will call the function and draws lines comming from the start point to this button
}

I hope this helps :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now