|
-
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)
}
}
}
-
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.
-
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.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); }
var portresetPos = new Array (7, 50, 7, 194, 7, 338, 7, 482, 0, 60, 0, 204, 0, 348); }
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.
-
Can anyone help with this please?
-
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]);
}
};
-
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
-
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;
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|