--------------------------------------------------------------------------------------------------------------
PHP CHANGE IN CODE AS2
MAKE 4 MOVIE CLIPS OR BUTTON WITH INSTANCE NAME
var btnArray:Array = new Array(mc1, mc2, mc3, mc4);
OR USE THIS CODE WITH BIG BRACKET
var btnArray:Array = [btn1_btn, btn2_btn, btn3_btn, btn4_btn]
-------------------------------------------------------------------------------------------------------------
import mx.transitions.Tween;
import mx.transitions.easing.*;
var btnArray:Array = new Array(mc1, mc2, mc3, mc4);
for (i=0; i<btnArray.length; i++) {
///initail state///
btnArray[i]._alpha = 10;
btnArray[i].enabled = true;
btnArray[i].id = i;
btnArray[i].onRollOver = function() {
//this._alpha = 100;
new Tween(this, "_alpha", Regular.easeIn, this._alpha, 100, 1, true);
};
btnArray[i].onRollOut = function() {
//this._alpha = 10;
new Tween(this, "_alpha", Regular.easeIn, this._alpha, 10, 1, true);
};
btnArray[i].onRelease = function() {
releaseF(this.id);
};
}
////onRelease function///
releaseF = function (rf) {
for (var i = 0; i<btnArray.length; i++) {
if (i != rf) {
this.btnArray[i].enabled = true;
new Tween(this.btnArray[i], "_alpha", Regular.easeIn, this.btnArray[i]._alpha, 10, 1, true);
//this.btnArray[i]._alpha = 10;
} else {
this.btnArray[i].enabled = false;
new Tween(this.btnArray[i], "_alpha", Regular.easeIn, this.btnArray[i]._alpha, 100, 1, true);
//this.btnArray[i]._alpha = 100;
}
}
};
=======================================================================
OR USE THIS CODE WITH BIG BRACKET
var btnArray:Array = [btn1_btn, btn2_btn, btn3_btn, btn4_btn]
======================================================================
import mx.transitions.Tween;
import mx.transitions.easing.*;
var btnArray:Array = [btn1_btn, btn2_btn, btn3_btn, btn4_btn]
for (i=0; i<btnArray.length; i++) {
///initail state///
btnArray[i]._alpha = 10;
btnArray[i].enabled = true;
btnArray[i].id = i;
btnArray[i].onRollOver = function() {
//this._alpha = 100;
new Tween(this, "_alpha", Regular.easeIn, this._alpha, 100, 1, true);
};
btnArray[i].onRollOut = function() {
//this._alpha = 10;
new Tween(this, "_alpha", Regular.easeIn, this._alpha, 10, 1, true);
};
btnArray[i].onRelease = function() {
releaseF(this.id);
};
}
=====================================================================
https://www.kirupa.com/forum/showthread.php?312905-AS2-Help-with-functions-applied-to-button-array
http://help.adobe.com/en_US/as2/reference/flashlite/WS5b3ccc516d4fbf351e63e3d118ccf9c47f-7ea2.html
=====================================================================
AS2 Help with functions applied to button array
Hi - I have some functions that when applied directly to buttons work as planned, but when I create a function from them to apply to the array, they fail to execute properly.
Trace tells me the arrays are being parsed correctly, so the problem is in the functions themselves.
This function is meant to set all 56 buttons to alpha 0, and as unselected.
What happens is the buttons flash onscreen at 100% before setting to alpha 0. They do behave as if unselected, but don't know if that's due to the code.
Code:
for (_root.i = 0;i<56;i++){
_root["btn"+_root.i].onEnterFrame = function() {
this._alpha = 0;
this.bSelected = false;
this.onEnterFrame = null;
}
}
This function should fade the button up on rollover. But on rollover the button only increase by 10% then stops. Each subsequent rollover increases it another 10%.
Code:
for (_root.i = 0;i<56;i++){
_root["btn"+_root.i].onRollOver = function() {
this._alpha<100 ? this._alpha += 10 : this.onEnterFrame = "";
}
}
This function should fade the button out on rollout. Since the rollover increases them only by 10% increments (above), the result is the buttons just bounce back and forth between alpha 20 and 30.
Code:
for (_root.i = 0;i<56;i++){
_root["btn"+_root.i].onRollOut = function() {
(this._alpha>20 && this.bSelected==false) ? this._alpha -= 10 : this.onEnterFrame = "";
}
}
Last one
this function should set several behaviors on release. Right now none of them appear to work.
Code:
for (_root.i = 0;i<56;i++){
_root["btn"+_root.i].onRelease = function() {
this.bSelected = true;
this.enabled = false;
pastBtn.enabled = true;
pastBtn._alpha = 20;
pastBtn.bSelected = false;
pastBtn = this;
}
}
Thanks for your help.
Last edited by stanmc; November 6th, 2008 at 03:51 PM. Reason: Update
November 7th, 2008, 09:19 AM#2
I blagg my way through most things action script but heres something pretty much the same as you are looking for ( i have set the button alpha to 10 so that the buttons can be seen also i have used the tween class for the fades
I USED THIS PHP CODE IN AS2
PHP Code:
import mx.transitions.Tween;import mx.transitions.easing.*;
var btnArray:Array = new Array(btn1_btn, btn2_btn, btn3_btn, btn4_btn);
for (i=0; i<btnArray.length; i++) {
///initail state///
btnArray[i]._alpha = 10;
btnArray[i].enabled = true;
btnArray[i].id = i;
btnArray[i].onRollOver = function() {
//this._alpha = 100;
new Tween(this, "_alpha", Regular.easeIn, this._alpha, 100, 1, true);
};
btnArray[i].onRollOut = function() {
//this._alpha = 10;
new Tween(this, "_alpha", Regular.easeIn, this._alpha, 10, 1, true);
};
btnArray[i].onRelease = function() {
releaseF(this.id);
};
}////onRelease function///releaseF = function (rf) {
for (var i = 0; i<btnArray.length; i++) {
if (i != rf) {
this.btnArray[i].enabled = true;
new Tween(this.btnArray[i], "_alpha", Regular.easeIn, this.btnArray[i]._alpha, 10, 1, true);
//this.btnArray[i]._alpha = 10;
} else {
this.btnArray[i].enabled = false;
new Tween(this.btnArray[i], "_alpha", Regular.easeIn, this.btnArray[i]._alpha, 100, 1, true);
//this.btnArray[i]._alpha = 100;
}
}
};
I'm sure someone else on here could make lighter work of it, anyway i hope it helps you out
November 7th, 2008, 12:28 PM#3
Manny - Thanks for your time. I'll give it a go and see what comes of it.
November 12th, 2008, 07:20 PM#4
Hi - This works great, but I have a couple of questions.
First the code as implemented.
Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
stop();
//button array
var navButton:Array = new Array();
navButton[0] = btn1;
navButton[1] = btn2;
navButton[2] = btn3;
navButton[3] = btn4;
navButton[4] = btn5;
navButton[5] = btn6;
navButton[6] = btn7;
navButton[7] = btn8;
navButton[8] = btn9;
navButton[9] = btn10;
etc.
//all buttons initial state
for (var i = 0; i < navButton.length; i++){
navButton[i]._alpha = 0;
navButton[i].enabled = true;
navButton[i].id = i;
navButton[i].onRollOver = function() {
//this._alpha = 100;
new Tween(this, "_alpha", Strong.easeIn, this._alpha, 100, 10, false);
};
navButton[i].onRollOut = function() {
//this._alpha = 20;
new Tween(this, "_alpha", Strong.easeOut, this._alpha, 10, 10, false);
};
navButton[i].onPress = function() {
pressF(this.id);
trace(this.id);
};
}
//onPress function
pressF = function (rf) {
for (var i = 0; i < navButton.length; i++) {
if (i != rf) {
navButton[i].enabled = true;
new Tween(this.navButton[i], "_alpha", Regular.easeIn, this.navButton[i]._alpha, 10, 10, false);
//this.btnArray[i]._alpha = 10;
} else {
navButton[i].enabled = false;
new Tween(this.navButton[i], "_alpha", Regular.easeIn, this.navButton[i]._alpha, 100, 10, false);
//this.btnArray[i]._alpha = 100;
}
}
};
//BEGIN BUTTONS
//button 1
btn1.onRelease = function() {
container_mc.loadMovie("movie1.swf");
}
//button 2
btn2.onRelease = function() {
container_mc.loadMovie("movie2.swf");
Two problems I'm having trouble with:
1. The button onRelease loadMovie functions at the end do not work, something in the code above is interfering. They work when that code is commented out.
2. In the pressF function (changed to onPress from onRelease to try and avoid conflict with the loadMovie onRelease for each button) I want this to only change the last button pressed from it's current 100% back down to 10%. Right now if I have not used any buttons, and click on one, all other buttons are revealed by changing to alpha 10. I want the user to have to discover the buttons via rollover first, before they are set to 10%.
Not sure I made sense but maybe you'll see what I mean.
November 13th, 2008, 01:11 PM#5
Don't know why this is, but I switched the function inside the
for (var i = 0; i < navButton.length; i++){
statement from onPress to onRelease, and made the link attached to each button an onPress function and it works.
BTW my final working code (no change to array or tween import already posted) in case someone looks for similar function is:
Code:
//all buttons initial state
for (var i = 0; i < navButton.length; i++){
trace(i);
navButton[i]._alpha = 0;
navButton[i].bSelected = false;
navButton[i].onRollOver = function() {
//this._alpha = 100
new Tween(this, "_alpha", Strong.easeIn, this._alpha, 100, 10, false);
};
navButton[i].onRollOut = function() {
//this._alpha = 20
new Tween(this, "_alpha", Strong.easeOut, this._alpha, 20, 10, false);
};
navButton[i].onRelease = function() {
this.bSelected = false;
this.enabled = false;
pastBtn.enabled = true;
pastBtn._alpha = 20;
pastBtn.bSelected = fasle;
pastBtn = this;
};
}
//BEGIN BUTTONS
//button 1
btn1.onPress = function() {
container_mc.loadMovie("movie1.swf");
}
//button 2
btn2.onPress = function() {
container_mc.loadMovie("movie2.swf");
}
etc.
EmoticonEmoticon