PDA

View Full Version : for loop question


Timon
01-31-2006, 03:49 PM
Hi,

ive got this code:



for (var i = 0; i<10; i++)
{
movieclip["button"+i].onPress = function() {loadVariables("php/page"+i".php",this, "GET");}}
}



But its not working, the button numbers are ok but every php file is page10.php , this is what I want:

The first i (behind button) has to be the same number as the second i. Is this possible? So when button 1 is pressed page 1 has to be loaded, when button 2 is pressed page 2 had to be loaded etc.

Thanx

sophistikat
01-31-2006, 03:57 PM
what is movieclip?
you had + i instead of + i +
you should be using LoadVars();
for (var i = 0; i<10; i++)
{
this["button"+i].onPress = function()
{
loadVariables("php/page" + i + ".php", this, "GET");
}
}

Timon
01-31-2006, 04:05 PM
what is movieclip?
you had + i instead of + i +
you should be using LoadVars();
for (var i = 0; i<10; i++)
{
this["button"+i].onPress = function()
{
loadVariables("php/page" + i + ".php", this, "GET");
}
}

hmm that doesnt work either, Ill show you the full code, than you can see wat movieclip is:

for (var i = 0; i<10; i++) {
movieclip.attachMovie("ball", "button"+i, i, {_x:oX+Math.cos(i*delta)*rad, _y:oY+Math.sin(i*delta)*rad});}

for (var i = 0; i<10; i++)
{
movieclip["button"+i].onPress = function()
{
loadVariables("php/page" + i + ".php", this, "GET");
}
}

by the way, when sould u be using LoadVars and when loadVariables? Whats the difference?

sophistikat
01-31-2006, 04:07 PM
for (var i = 0; i < 10; i++) {
var n = movieclip.attachMovie("ball", "button"+i, i, {_x:oX+Math.cos(i*delta)*rad, _y:oY+Math.sin(i*delta)*rad});
n.onPress = function () {
loadVariables("php/page" + i + ".php", this, "GET");
}
}

Timon
01-31-2006, 04:56 PM
for (var i = 0; i < 10; i++) {
var n = movieclip.attachMovie("ball", "button"+i, i, {_x:oX+Math.cos(i*delta)*rad, _y:oY+Math.sin(i*delta)*rad});
n.onPress = function () {
loadVariables("php/page" + i + ".php", this, "GET");
}
}

hmm doesnt work, it keeps getting page10.php

if I trace i like this, it gives me '10' on every button


for (var i = 0; i < 10; i++) {
var n = movieclip.attachMovie("ball", "button"+i, i, {_x:oX+Math.cos(i*delta)*rad, _y:oY+Math.sin(i*delta)*rad});
n.onPress = function () {
trace(i);
loadVariables("php/page" + i + ".php", this, "GET");
}
}

sophistikat
01-31-2006, 05:00 PM
you don't have to keep 'quoting' my previous message, i'll know what you're talking about
for (var i = 0; i < 10; i++) {
var n = movieclip.attachMovie("ball", "button"+i, i, {_x:oX+Math.cos(i*delta)*rad, _y:oY+Math.sin(i*delta)*rad});
n.myNum = i;
n.onPress = function () {
loadVariables("php/page" + myNum + ".php", this, "GET");
}
}

Timon
01-31-2006, 05:08 PM
this gives me 9 on each button

for (var i = 0; i < 10; i++) {
var n = movieclip.attachMovie("ball", "button"+i, i, {_x:oX+Math.cos(i*delta)*rad, _y:oY+Math.sin(i*delta)*rad});
n.myNum = i;
n.onPress = function () {
trace(n.myNum);
loadVariables("php/page" + myNum + ".php", this, "GET");
}
}

:confused:

sophistikat
01-31-2006, 05:19 PM
in your trace and in your loadVariables: this.myNum

Timon
01-31-2006, 05:33 PM
yeah! Thanx dude!