all groups > flash actionscript > january 2005 >
You're in the

flash actionscript

group:

a function to assign on(release) function to buttons..


Re: a function to assign on(release) function to buttons.. Byron Canfield
1/31/2005 9:02:17 AM
flash actionscript: [quoted text, click to view]
============================================================================
====
[quoted text, click to view]

The primary problem is here:

myURL = _root.subButtonURL[buttonNum-1][i];
this["subbutton"+(i+1)+"_mc"].onRelease = releaseSubButton(myURL);

The value of "myURL" in the button event is not the value of "myURL" at the
time the button event is created, but rather, it is the value of "myURL"
when the button event executes (when it's released), which, since the loop
has completely finished running, is the same for all buttons.


--
--------
Reality will not be altered to comply with preconceived notions.

Byron "Barn" Canfield

a function to assign on(release) function to buttons.. ¶Ç»¡¤§¯«
1/31/2005 10:04:00 PM
Here is my part of code, which is to achieve the URLs stored in a 2-D array
: subButtonURL[x][y]
================================================================================

function showSubMenu(x, y, buttonNum, subbuttonNum) {
hideSubMenu();
for (i=0; i<subbuttonNum; i++) {
var tempi:Number = i;
var tempbuttonNum:Number = buttonNum;
this["subbutton"+(i+1)+"_mc"]._visible = true;
this["subbutton"+(i+1)+"_mc"]._x = x+10+(80*i);
this["subbutton"+(i+1)+"_mc"]._y = y+23;
this["subbutton"+(i+1)+"_mc"].subbutton_lb.text =
_root.subButtonText[buttonNum-1][i];
var myURL:String;
myURL = _root.subButtonURL[buttonNum-1][i];
this["subbutton"+(i+1)+"_mc"].onRelease = releaseSubButton(myURL);
}
}

function releaseSubButton(myURL) {
getURL(myURL);
trace(myURL);
}
================================================================================
I notice that the getURL(myURL) sentence keep on running and get different
URL when "showSubMenu" function is being ran.
I want to write a function to get the URLs at the 1st frame of 1st layer.
How should I rewrite the program? Thank you.

AddThis Social Bookmark Button