A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Array not transmitting value

  1. #1
    Member
    Join Date
    Jan 2003
    Posts
    65

    Array not transmitting value

    Hello people,
    I have an array placed in movieclip which I am using to store the x and y values of other movieclip clips. The values work when the clip initially loads (it moves the targeted clips to the assigned positions) but when I reset the positions of the clips in the array (using another button) then I hover over the array assigned button 'portfolio_btn' nothing happens.

    I'm using flash 8 AS2

    Any help with this would be much appreciated.



    PHP Code:
    onClipEvent(enterFrame){
    var 
    portNav:Array = [

            
    //
            
    _root.nav.bottomline.nxPos 7,
            
    _root.nav.bottomline.nyPos 512,
            
    //
            
    _root.nav.secondline.nxPos 7,
            
    _root.nav.secondline.nyPos 164,
            
    //
            
    _root.nav.thirdline.nxPos 7,
            
    _root.nav.thirdline.nyPos 368,
            
            
    _root.nav.no1text.nxPos 0,
            
    _root.nav.no1text.nyPos 30,
            
            
    _root.nav.no3text.nxPos 0,
            
    _root.nav.no3text.nyPos 378
        
    ];
        
        
        if(
    _root.page == "home"){
        
    _parent.portfolio_btn.onRollOver = function(){
        
    portNav
        trace
    (portNav)
        }
    }


  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    You should just store values in an array - strings or numbers:

    xPositions = new Array(7,7,7,0,0);

    Then

    trace(xPositions[0]);

    to show the first value in the array.

    All of your code is in an onEnterFrame which means it repeats over and over as fast as your movie's fps. Is that what you want?

    You want to assign the function to the button only once, so move it out of the onEnterFrame.

  3. #3
    Member
    Join Date
    Jan 2003
    Posts
    65

    Thumbs up Thanks Moot

    I have removed the code from the onEnterFrame statement and created two arrays 'portresetPos' and 'clipPos'

    PHP Code:
        var clipPos = new Array (topline.nxPostopline.nyPossecondline.nxPossecondline.nyPosthirdline.nxPosthirdline.nyPosbottomline.nxPosbottomline.nyPosno1text.nxPosnyPosno2text.nxPos,  no2text.nyPos,  no3text.nxPos,  no3text.nyPos);
        }

    var 
    portresetPos = new Array (75071947338748206002040348);
        } 
    The first array 'var clipPos' stores names of the x and y function used to control movieclips.

    The second array stores the x y values. The position of the values is in correlation to relevant movieclip the first array.

    How would I go about combining the two arrays
    e.g
    topline.nxPos = 7
    topline.nyPos =50

    To create a function that I could simply place in the onRollOver command?
    Any help is much appreciated.
    Last edited by sugarkid; 03-12-2009 at 06:05 AM.

  4. #4
    Member
    Join Date
    Jan 2003
    Posts
    65
    Can anyone help with this please?

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Have you tried doing something like this...
    Code:
    var clipPos = new Array(topline.nxPos, topline.nyPos, secondline.nxPos, secondline.nyPos, thirdline.nxPos, thirdline.nyPos, bottomline.nxPos, bottomline.nyPos, no1text.nxPos, nyPos, no2text.nxPos, no2text.nyPos, no3text.nxPos, no3text.nyPos);
    //
    btn1.onRollOver = function() {
    	var portresetPos = new Array(7, 50, 7, 194, 7, 338, 7, 482, 0, 60, 0, 204, 0, 348);
    	for (i in clipPos) {
    		clipPos[i] = portresetPos[i];
    		trace(clipPos[i]);
    	}
    
    };
    btn2.onRollOver = function() {
    	var portresetPos = new Array(27, 150, 7, 194, 7, 338, 7, 482, 0, 60, 0, 204, 0, 348);
    	for (i in clipPos) {
    		clipPos[i] = portresetPos[i];
    		trace(clipPos[i]);
    	}
    };

  6. #6
    Member
    Join Date
    Jan 2003
    Posts
    65

    Smile Almost dawsonk

    I tried your code and it worked but not as I expected as my previous explanation wasn't clear enough. I need the function to output the text

    PHP Code:
    topline.nxPos 7
    topline
    .nyPos =50 
    into the function i.e

    PHP Code:
    btn1.onRollOver = function() {
    topline.nxPos 7
    topline
    .nyPos =50

    using the two arrays was an attempt at cutting down the amount of code. The function currently looks like this. Which works fine but is too lengthy as there are many buttons.

    PHP Code:
      _parent.portfolio_btn.onRelease = function(){
            
    _root.nav.topline.nxPos 7;
            
    _root.nav.topline.nyPos 20;
            
    //
            
    _root.nav.bottomline.nxPos 7;
            
    _root.nav.bottomline.nyPos 512
            
    //
            
    _root.nav.secondline.nxPos 7;
            
    _root.nav.secondline.nyPos 164;
            
    //
            
    _root.nav.thirdline.nxPos 7;
            
    _root.nav.thirdline.nyPos 368;
            
            
    _root.nav.no1text.nxPos 0;
            
    _root.nav.no1text.nyPos 30;
            
            
    _root.nav.no3text.nxPos 0;
            
    _root.nav.no3text.nyPos 378;
        } 
    I hope that makes sense

  7. #7
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    Are the numbers different for each button?

    Buttons can share a function if that helps. Here's how you can use arrays to do the onRelease function you showed.

    Code:
    var clipNames = new Array("topline","bottomline","secondline","thirdline","no1text","no3text");
    var nxPosArray = new Array(7,7,7,7,0,0);
    var nyPosArray = new Array(20,512,164,368,30,378);
    
    function buttonReleased(){ 
      for(var i=0; i<clipNames.length; i++){
        _root.nav[clipNames[i]].nxPos = nxPosArray[i]; 
        _root.nav[clipNames[i]].nyPos = nyPosArray[i];
      }
    }
    
    _parent.portfolio_btn.onRelease = buttonReleased;
    anyButton.onRelease = buttonReleased;

  8. #8
    Member
    Join Date
    Jan 2003
    Posts
    65
    Thanks for your help moot. This works a treat!!
    There are different numbers for each button is it best to create a separate array and function for each?
    Last edited by sugarkid; 03-18-2009 at 03:31 AM.

  9. #9
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    Good news, you're welcome.

    Ideally, you should use mathematical equations to generate the numbers instead of storing them.

    Yes, you can use seperate arrays for each button. You can store the arrays in the button object. When a button calls a function, you can refer to that button using "this":

    Code:
    var clipNames = new Array("topline","bottomline","secondline","thirdline","no1text","no3text");
    _parent.portfolio_btn.nxPosArray = new Array(7,7,7,7,0,0);
    _parent.portfolio_btn.nyPosArray = new Array(20,512,164,368,30,378);
    
    
    function buttonReleased(){
      trace("this: " + this);
      for(var i=0; i<clipNames.length; i++){
        _root.nav[clipNames[i]].nxPos = this.nxPosArray[i]; 
        _root.nav[clipNames[i]].nyPos = this.nyPosArray[i];
      }
    }
    
    _parent.portfolio_btn.onRelease = buttonReleased;
    anyButton.onRelease = buttonReleased;

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center