LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




ReplyREPLY THREAD
 
Thread Tools Display Modes
  #1  
Old 02-09-2009, 05:12 PM
stevenbernard stevenbernard is offline
Registered User
 
Join Date: Jan 2009
Location: United Kingdom
Posts: 9
Rep Power: 0
stevenbernard is on a distinguished road
Drawing graphs using lineTo function and array vakues

Hi guys and gals,

I have managed to draw a simple graph with the lineTo function pulling in data from an array.

The only problem I have is that the line joins the last data point to the first creating a closed shape instead just a 'wiggly' line

If anyone can help me solve this I would be eternally grateful

Best
Steve
Attached Files
File Type: zip Chart-em.fla.zip (6.0 KB, 2 views)
Reply With Quote
  #2  
Old 02-10-2009, 04:39 AM
twocs twocs is offline
Registered User
 
Join Date: Feb 2009
Location: Taiwan, Province Of China
Posts: 2
Rep Power: 0
twocs is on a distinguished road
Check what you loop over

The error: Don't iterate through all the "n", because you are drawing each line three times, hence the loop. The quick fix: Remove

Code:
for (var n=0; n<myArray.length; n++) { ... }
and instead use

Code:
var n = 0;
The longer way, but will work better because some lines may be longer than others:

Code:
// set up an array for different colors for each line
var colorArray:Array = [0x000000, 0xff0000, 0x0033cc];

// iterate through each of the lines
for (var n:Number = 0; n<myArray.length; n++)
{
    // create an empty movie clip called "n" for the line at depth n
    this.createEmptyMovieClip(n, n);
    
    // set the line style of the line, thickness = 2 and color from colorArray
    eval(n).lineStyle(2, colorArray[n]);
    
    // set up the original point of the line
    eval(n).moveTo(0, 0);
    
    // iterate through the different points in the line
    for (var i = 0; i<myArray[n].length; i++) {
        
        // draw a line that connects to the next point in the line
        eval(n).lineTo(i*10, myArray[n][i]);
    }
}
Note: eval is deprecated in AS 3
Reply With Quote


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Applying a master function to any array (dynamic targeting syntax) freaksarise Flash CS5 1 04-07-2011 03:36 PM
Decompiling haXe puppy Members Cafe 3 12-16-2008 10:38 AM
Function Consolidation Help SpectacularStuf Flash CS3 / Flash 9 0 09-29-2007 03:20 AM
Huh? Nonsense Newbies 2 01-06-2007 12:15 AM
Help with a Tough Array Randomization/Shuffle Problem TheMediaBoy Actionscript 2.0 10 07-21-2006 09:05 AM




All times are GMT. The time now is 11:48 AM.