SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ActionScript - redisplaying data up to a certain point

    Hello all

    First post in this forum for me.

    I will try to explain the problem I am currently facing:

    I am trying to plot data stored in an array. I am able to plot the complete data at once but I would like to be able to step back and for in the display.
    I have created a variable "current" which is incremented by a click on one button and the data is plotted up to "current". This works but I cannot get it to work to step back when I click the button I created for this whichs decreases "current" by one.

    Example:
    - the user has clicked three times on the button "next"
    => "current" is 3
    => the first three elements of the data are plotted

    - the user now clicks once the button "prev"
    => "current" is 2
    => now only the first two elements should be displayed

    The movieclip is created using _root.createEmptyMovieClip(...);

    On a related note, I noticed that there seems to bit of a performance hit if I create several MovieClips using createEmptyMovieClip(). The moving around of a zoomed clip is really slow. I have four arrays to plot and created a MovieClip for each in order to make it easier to show or disable each.
    Did somebody also encouter this?

    I hope, I explained it properly.

    Thanks in advance,
    Christian

  2. #2
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'd recommend making the "current" vairable global.
    Code:
    _global.current = 0;
    Then for the buttons you'd have;
    Code:
    on(release){
    _global.current += 1;
    }
    // above code for the incrementing button
    
    on(release){
    _global.current -= 1;
    }
    // above code for the decrementing button
    If you had a button that you press to output the data, you could do
    Code:
    on(release){
    displayOutput();
    }
    And the function would be something like...
    Code:
    function displayOutput(){
    for (i=0; i<_global.current; i++) {
    trace(Array[" + i + "] : " + arrName[i] + "." );
    }
    }
    Eh?

  3. #3
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Quote Originally Posted by aaron.martone
    I'd recommend making the "current" vairable global.

    [...]

    Eh?
    Thank you for your answer

    What you posted is more or less what I have come up with. I didn't make current global but this does not seem to be the problem. I will post a simplified version of the code I have:

    Code:
    // "global" values for drawing the lines
    var xoffset = 10;
    var yoffset = 10;
    var between = 10;
    var scaley = 1.5;
    var ROUNDS = 25;
    var current = 0;
    
    // two records
    var records =  new Array(0, 12, 8, 12, 20, -10, 30, 12, 40, -20, -14, -10, 8, 4, 0);
    var records2 = new Array(0, 14, 2, 1, 30, -1, 23, 32, 43, -20, -30, -10, 3, 4, 0);
    
    // implementation of Java's drawline
    MovieClip.prototype.drawLine = function(x1, y1, x2, y2) {
    	this.moveTo(x1, y1);
    	this.lineTo(x2, y2);
    }
    
    // plot data which is stored in an array
    MovieClip.prototype.plotData = function(records) {
    	for (var i = 0; i < Math.min(current, records.length); i++) {
    		// the next point in the array 
    		var j = Math.min(i + 1, records.length - 1);
    		
    		this.drawLine(
    			i * between, 
    			scaley * -records[i], 
    			j * between, 
    			scaley * -records[j]
    		);
    	}
    }
    
    // create to movie clips
    var plot1 = _root.createEmptyMovieClip("p1", 1);
    var plot2 = _root.createEmptyMovieClip("p2", 2);
    
    plot1.lineStyle(1, 0xFF0000, 100);
    plot2.lineStyle(1, 0x00FF00, 100);
    
    plot1._x = xoffset;
    plot1._y = 40;
    
    plot2._x = xoffset;
    plot2._y = 40;
    
    plot1.plotData(records);
    plot2.plotData(records2);
    And this is the code for [previous] and [next] buttons I use:

    previous:
    Code:
    on(release) {
    	current = Math.max(0, current - 1);
    	plot1.plotData(records);
    	plot2.plotData(records2);
    }
    next:
    Code:
    on(release) {
    	current = Math.min(current + 1, ROUNDS);
    	plot1.plotData(records);
    	plot2.plotData(records2);
    }
    Now when I click on next (the second button in the attached file, the next points are drawn. However clicking on previous (first button) it doesn't go back.
    Perhaps I have to clear the already drawn lines and display these afterwards?

    Thanks,
    Christian
    Attached Files Attached Files

  4. #4
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have almost solved my problem.
    Going back and forth is possible now.
    The only problem currently is when I click on one of the buttons on upper right and hit back several times and hit the same button again, the corresponding line does not show up at once. I have to click back / for again to make it visible.

    link: http://christian-sobetzko.de/plotter.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •