Hi Karl, 
 
Hahahaha, AS3 is very much easier then AS2. 
But can be a little tricky to grasp when you are switching. 
Believe me, once you see the structure, you don't understand that AS2 has ever 
existed. 
 
First the Q: How do you use a button instead of a MC. 
There is no difference, they are both Objects with each some specific 
properties. 
The button is in fact a movieclip with just a timeline of 4 states. 
I recommend never to use Flash Components(!). 
Create youre own button or movieclip. 
When you create a graphic and transform (F8) it into a Symbol you can choose to 
set it as a MC or Button. 
I prefer MC always and write my own class to deal with the states. 
I will send you some examples in a following mail. 
 
In this mail I will address your code problem as is. 
I always look at code to see if something is redundant. 
So if there is ANYTHING I discover is present more then once, I create 
something 
so there is only 1 of it, and reuse that as often as needed. 
 
In your case I can't see if the buttons are put on stage phisically or with 
code. 
I always use code only, my stage stays empty and I have no frames on the 
timeline! 
My guess is that in this case the buttons are already on the stage, so I will 
set the code as follows: 
 
//put all the button names in this array 
var aButtons:Array = [ button1_btn, button2_btn]; 
var idx:int = -1;  //no button selected yet 
 
for (var i:uint = 0; i < aButtons.length; ++i){ 
 aButtons[i].buttonMode = true; 
 aButtons[i]..mouseChildren = false; 
 aButtons[i].addEventListener(MouseEvent.CLICK, btnClickHandler, false, 0, 
true); 
 aButtons[i].addEventListener(MouseEvent.ROLL_OVER, btnOverHandler, false, 0, 
true); 
 aButtons[i].addEventListener(MouseEvent.ROLL_OUT, btnOutHandler, false, 0, 
true); 
} 
 
function btnClickHandler(e:MouseEvent):void{  
 //get the position in the array of the clicked button 
 idx = aButtons.indexof(e.target); 
 switch (idx) { 
        case 0: 
        this.gotoAndStop("divinedivers"); //goto frame divinedivers in this MC 
        break; 
        case 1: 
        this.gotoAndStop("scubadudes"); //got frame scubadudes in this MC 
        break; 
 } 
} 
 
function btnOverHandler(e:MouseEvent):void { 
 //get the position in the array of the clicked button 
 idx = aButtons.indexof(e.target); 
//RENAME THE FRAME TO 'over' !! 
aButtons[idx].gotoAndStop("over"); //toggle this button MC frame 
} 
function btnOutHandler(e:MouseEvent):void { 
 //get the position in the array of the clicked button 
 idx = aButtons.indexof(e.target); 
//RENAME THE FRAME TO 'out' !! 
aButtons[idx].gotoAndStop("out"); //toggle this button MC frame 
} 
 
I typed this instantly in this mail, so watch for a possible typo? 
I go to dinner now, and create and send the promised examples after that. 
 
If you have problems with the code above, please tell me. 
For simplicity, I suggest mailing a FLA to eachother. 
 
regards 
Cor 


---- Karl DeSaulniers <k...@designdrumm.com> schreef:
Hello All,
Long time. If your available at the moment, I could use your help with  
some AS3.
I finally got an AS3 job! Yay! But I am stuck on the most simple of  
things.
All I am trying to do is make some buttons work... lol
Here is my code.

button1_btn.buttonMode = true;
button2_btn.buttonMode = true;
button1_btn.useHandCursor = true;
button2_btn.useHandCursor = true;
button1_btn.mouseChildren = false;
button2_btn.mouseChildren = false;

button1_btn.addEventListener(MouseEvent.CLICK, function()  
{ changeSelect(1); });
button2_btn.addEventListener(MouseEvent.CLICK, function()  
{ changeSelect(2); });
button1_btn.addEventListener(MouseEvent.ROLL_OVER, function()  
{ toggleB1(2); });
button2_btn.addEventListener(MouseEvent.ROLL_OVER, function()  
{ toggleB2(2); });
button1_btn.addEventListener(MouseEvent.ROLL_OUT, function()  
{ toggleB1(1); });
button2_btn.addEventListener(MouseEvent.ROLL_OUT, function()  
{ toggleB2(1); });

function changeSelect(p):void {
                switch (p) {
                        case 1:
                        this.gotoAndStop("divinedivers"); //goto frame 
divinedivers in this  
MC
                        break;
                        case 2:
                        this.gotoAndStop("scubadudes"); //got frame scubadudes 
in this MC
                        break;
                }
}

function toggleB1(f):void {
                button1_btn.gotoAndStop(f); //toggle this button MC frame
}

function toggleB2(f):void {
                button2_btn.gotoAndStop(f); //toggle this button MC frame
}

Why does AS3 have to make things so difficult for something so simple??
What the heck am I doing wrong???

Also, how do you use just a button instead of a mc?
I tried using just a button and it wouldn't even switch to the over  
state that is inside the button!!?

AS2 is just so much more simple... sigh*

TIA,

Karl DeSaulniers
Design Drumm
http://designdrumm.com

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to