|
-
functions with arrays
function does not works with array in following code:
in reference image these five are the movieclips on the stage and their instance names are same as the array items. see attachment for reference.
Code:
var mainBtnsArr:Array = ["chapters", "projects", "exercises", "skills", "glossary"]; for (i=0; i<mainBtnsArr.length; i++) { mainBtn = mainBtnsArr[i]; mainBtnsArr[i].onPress = function() { trace("working"); }
Any help please?
-
.
Hi,
where is the attachment?
-
.
-
main.jpg
sorry my fault..... now please find attachment.
-
.
Hi,
Here you go, you were on the right track though.
PHP Code:
var mainBtnsArr:Array = [chapters, projects, exercises, skills, glossary];
for (i = 0; i < mainBtnsArr.length; i++)
{
mainBtnsArr[i].TheNum = [i + 1];
mainBtnsArr[i].onPress = function()
{
trace(this.TheNum + " " + this._name + " : " + " Pressed");
};
mainBtnsArr[i].onRelease = mainBtnsArr[i].onReleaseOutside = function()
{
trace(this.TheNum + " " + this._name + " : " + " Released");
};
mainBtnsArr[i].onRollOver = function()
{
// do something else
};
mainBtnsArr[i].onRollOut = mainBtnsArr[i].onDragOut = function()
{
// do something else
};
}
-
Prid - Outing
or if you want to keep you Array items as Strings, you can use this:
Code:
var mainBtnsArr:Array = ["chapters", "projects", "exercises", "skills", "glossary"];
for (i=0; i<mainBtnsArr.length; i++) {
btnClick(this[mainBtnsArr[i]]);
}
function btnClick(btn){
btn.onPress = function(){
trace("working");
}
}
the key is this[mainBtnsArr[i]], because it looks for an object with the value of the string. You were only giving a String onPress handler
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
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
|