Copy link to clipboard
Copied
How do i create a button that would switch out a symbol in a flash animation??
Copy link to clipboard
Copied
Can you describe the situation with more detail? What code would you use to switch out the symbol without a button?
Copy link to clipboard
Copied
AS3 - want to show 4 different shoes at the beginning of movie, you click on one and the person in the animation wears that pair of shoes for the remainder of movie.
Copy link to clipboard
Copied
How is the animation done? Does it involve timeline tweening?
Copy link to clipboard
Copied
yes the shoe does move back and forth. It is actually for demonstrating how a hydraulic brake line works. Thought it would be kind of fun in the beginning to be able to pick a shoe.
Copy link to clipboard
Copied
This is the movie AC hydraulicBrakeSystem
Copy link to clipboard
Copied
One simple way of managing this would be to have the shoe as a movieclip with 4 frames. Each frame would be a different colored shoe and the first frame would have a stop(); command in it. Then create the 4 buttons by using the same shoe movieclip 4 times. Give the instance name "shoe" to the one in the diagram, and name the buttons "b1" thru "b4". The code for the buttons and changing the shoe color could be...
for(var i:int=1; i<5; i++){
this["b"+String(i)].gotoAndStop(i); // to adjust the button color choices
this["b"+String(i)].addEventListener(MouseEvent.CLICK, changeColor); // assign listeners to buttons
}
function changeColor(evt:MouseEvent):void {
shoe.gotoAndStop(Movieclip(evt.currentTarget).currentFrame); // change the shoe frame
}
Copy link to clipboard
Copied
Great idea! i will give it a try, thanks.
Copy link to clipboard
Copied
got this error: 1180: Call to a possible undefined method Movieclip column 23 of this line:
shoe.gotoAndStop(Movieclip(evt.currentTarget).currentFrame); // change the shoe frame
Copy link to clipboard
Copied
A typo on my part.... That should be MovieClip
Copy link to clipboard
Copied
Hey Ned, thanks again for your assistance. I don't get any errors now but the four buttons i made all are showing the first shoe and when rolled over they cycle through the 4 shoes and when clicked the "shoe" on the brake pedal doesn't change. Any idea what i am doing wrong? Here it the animation AC hydraulicBrakeSystem Thanks
Copy link to clipboard
Copied
What code are you using? Rollovers appear to be used but were not part of what I offered and are likely to interfere.
Copy link to clipboard
Copied
as3, and wish I knew it better than I do.
Copy link to clipboard
Copied
I mean the actual code... show it.
Copy link to clipboard
Copied
I made a quick example file for you to look at using the code I showed (with the fix)...
http://www.nedwebs.com/Flash/AS3_change_shoe.fla
in case you missed doing it, be sure to check how the instance names are assigned for each object on the stage... select one and look in the Properties panel for its name.
Copy link to clipboard
Copied
Got it, thanks so much. What i did wrong is made the 4 shoes with the movie clip inside of a button instead of just leaving the 4 shoe movie clips on the stage. Thanks, again.
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now