Hi guys,
I have a question hope someone can help me.
Well I have a couples of buttons with some effects inside them (motion tweens, labels, etc).
I know in AS2 we can actually set codes to an object like the button itself.
But how I can archive this using AS3? I mean what I need to do (because I can't set codes to the object in AS3) for make my buttons run the frames inside them?
For example in AS2 I can set the button (object) with this code and it will run the labels, etc. into it:
on (rollOver) {
gotoAndPlay ("go1");
}
on (rollOut) {
gotoAndPlay ("go2");
}
on (rollOver) {
gotoAndPlay ("go3");
}
on (rollOut) {
gotoAndPlay ("go4");
}
on (release) {
getURL ("http://www.anysite.net", _self);
}
Thanks in advance and sorry about my english.
I found this yesterday and problaby is the replacement.
mybutton.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
mybutton.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut, false, 0, true);
function manageMouseOver(event:MouseEvent):void{
gotoAndPlay ("go1");
}
function manageMouseOut(event:MouseEvent):void{
gotoAndPlay ("go2");
}
But either I place this code (inside or outside the button), don't work.
If I place it inside the button I get a error that my property (the button instance) isn't defined but it 's. I try changind the instance name of my button (movie clip) but still not find it.
Ideally you should keep all code in one place, it just makes life so much easier when you don't have to hunt down different code locations. There is no rule that says you have to, but it is a good habit to try to get into (though some designs are easier for some people to manage with code scattered around the timeline). The one place where most people choose when they code within the fla is frame 1 of the main timeline.
So if you put that code into the main timeline, and you name your button "mybutton", then the only thing I can see that needs changing for your code is that you need to tareget the movieclip in your event handler functions...
function manageMouseOver(event:MouseEvent):void{
mybutton.gotoAndPlay ("go1");
}
function manageMouseOut(event:MouseEvent):void{
mybutton.gotoAndPlay ("go2");
}
got it! Murphy, but what happen if I want 4 labels in total. I mean if I have go1, go2, go3 and go4?
What happen if I need that the Over event run "go1" and "go3" and the Out event run "go2" and "go4"?
Maybe:
function manageMouseOver(event:MouseEvent):void{
mybutton.gotoAndPlay ("go1");
mybutton.gotoAndPlay ("go3");
}
function manageMouseOut(event:MouseEvent):void{
mybutton.gotoAndPlay ("go2");
mybutton.gotoAndPlay ("go4");
}
That is not a correct answer. You cannot tell a movieclip to gotoAndPlay() two different places at the same time. Only the last one called will end up playing.
(and you cannot award yourself points if that is what you wanted to do... you can only award points to others that respond to your posting)
Well, inside my button (which is a MC) I create another movie clip invisible (called home_mc). Then using the code snippets I reference the "home_mc" with this below:
/* Mouse Over Event */
home_mc.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler_1);
function fl_MouseOverHandler_1(event:MouseEvent):void
{
gotoAndPlay ("go1");
gotoAndPlay ("go3");
}
/* Mouse Out Event */
home_mc.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_2);
function fl_MouseOutHandler_2(event:MouseEvent):void
{
gotoAndPlay ("go2");
gotoAndPlay ("go4");
}
Guess what... is working perfectly!
Now about the points... for me that is not impt. (I don't read the rules!) so done, I've undo that!
Anyway thanks for your anwsers! I really appreciate it.
There are no rules about marking your own entries as correct answers... it is perfectlyt legitimate to do when the answer is correct. The only problem is yours was not correct, and by what you show now it remains incorrect. But if you are happy with it as it is, I won't try to pursuade you otherwise.
North America
Europe, Middle East and Africa
Asia Pacific