Buttons whos Actions Depend on States of other Buttons -HOW?

  • BENBOB
  • Novice
  • Novice
  • BENBOB
  • Posts: 17

Post 3+ Months Ago

Hi,

I’ve made a 3D animation as a background to my homepage, and have imported it into Flash CS3 as a series of still TIFF images (one image on each frame).

Now I am looking to control this animation using a series of 9 buttons. At the moment each button does the following:

Button1: Play frames 0120. Stop.
Button2: Play frames 2130. Stop.
Button3: Play frames 3140. Stop.
…etc.

However, I want to make each button’s action dependant on the states of the other buttons:

When the user presses any of the 8 buttons other than the one that is currently engaged, I want the animation relating to the button that is currently engaged to be played in reverse, and then the animation belonging to the button that has just been pressed to be played! ":shock:"

For example, if Button 1 has been pressed, then the user presses Button 2, I want frames 2001 and then frames 2130 to be played. Another example; Button 3 is engaged, user presses Button 1 – frames 4031 should be played and then frames 0120.

If anyone could help me with the ActionScript to perform this (ideally AS3 but AS2 is fine) then I would be extremely, extremely grateful.

Thanks in advance for any comments. :)
Ben.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1827
  • Loc: In the Great White North

Post 3+ Months Ago

I may be wrong but I'm not aware of any way to "play the timeline backward" ususally when you see the timeline doing that sort of effect its because the images exist in order twice. The first time the images are placed left to right 1 to 10 and the second time they are placed left to right 10 to 1.

it would be a lot easier if you didn't place the images on frames and instead loaded them in via script. In that case you could actually display the images completely independant of the timeline by swapping depths, etc. This gives the illusion of animation (similar to individual frames on the timeline) but you can do a little math (current Image + 1 or current Image - 1) to figure out what order to display things.
  • BENBOB
  • Novice
  • Novice
  • BENBOB
  • Posts: 17

Post 3+ Months Ago

OK that makes sence, thank you very much for that. :)


Would you be able to offer me any help with the Actionscript relating to how a particular button responds according to which other button has been pressed?

For instance, there is a difference responce to Button 2 being pressed while Button 1 is engaged, than if Button 3 is pressed while Button 1 is engaged. E.g.

IF Button 1 Engaged AND Button 2 Pressed => Play frames 34-55.
IF Button 1 Engaged AND Button 3 Pressed => Play frames 43-67.

Is it possible to use "IF & AND statements" in ActionScript?
  • DPZero
  • Beginner
  • Beginner
  • User avatar
  • Posts: 48

Post 3+ Months Ago

I use a different method to work around this situation, as following:

-create an 'intro' and 'outro' for each menu item. Let's say menu item 1 intro starts at frame 1 and ends at frame 10 (where the movie stops in order to show the item). The intro starts from a blank screen and ends with the item fully displayed. The 'outro' starts at frame 10 and ends at frame 19, being the reverse of the 'intro'.

Now scripting.

-you need to use a variable, which will be given the value of the item that needs to be displayed. So, i=1 for the first menu item, 2 for the second and so on.

-at the end of each 'intro', where the menu item is fully shown, you need to place a script that checks if the item shown is the one which is supposed to (for item 1: if i=1, stop; the movie will keep playing if it's not supposed to show item 1)

-at the end of each 'outro', you need to place the 'goto' script, something similar to 'if i=1, gotandplay frame 1, if i=2 gotoandplay frame 20 etc)

-each button needs to have the i=1,2,3 etc and play actions attached

You probably figured how this works by now.
When you press a button, the 'outro' animation of the item being displayed starts and when it's finished, the movie will jump to the 'intro' of item i. The movie will then stop when item i is fully displayed. You need to check if the item shown is the correct one to prevent any mis-jumps from buttons being pressed quickly one after another :)

Hope this helped :)

PS: you should do your animations in Flash, not import them frame by frame :P
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1827
  • Loc: In the Great White North

Post 3+ Months Ago

DPZero's way will work but it gets you back to a timeline issue thats a lot harder to control in the long run.

To answer your question you can use if/else to check conditions as well as "and" and "or" within the conditions.

typical if/else in AS2 (I don't know how it works in AS3 since I haven't had time to learn the new hotness)
Code: [ Select ]
if(myVariable == "someString"){
// perform this code
}else{
// perform this other code
}

// conditions:
// <= less than or equal to
// >= greater than or equal to
// == exactly equal to
// !=  not equal to
// <  less than
// >  greater than
  1. if(myVariable == "someString"){
  2. // perform this code
  3. }else{
  4. // perform this other code
  5. }
  6. // conditions:
  7. // <= less than or equal to
  8. // >= greater than or equal to
  9. // == exactly equal to
  10. // !=  not equal to
  11. // <  less than
  12. // >  greater than


you can also do multiple conditions inside an if statement using "AND" ( && ) and "OR" ( || )
Code: [ Select ]
if(myVar1 == 2 && myVar2 < 30){
// perform actions when myVar1 is equal to 2 and myVar2 is less than 30
}else{
// condition isn't met do this....
}
  1. if(myVar1 == 2 && myVar2 < 30){
  2. // perform actions when myVar1 is equal to 2 and myVar2 is less than 30
  3. }else{
  4. // condition isn't met do this....
  5. }

You might also want to look up how to use case statements in flash. These are a better way to deal with a long list of conditions (like which button was called)


I think I would build a function that modifies a range of image numbers
Code: [ Select ]
function moveForward(startFrame, endFrame){
// generic code to transform images that you can reuse
}
  1. function moveForward(startFrame, endFrame){
  2. // generic code to transform images that you can reuse
  3. }



Here's an example of something I was just working on using the swap depths to fake animation. Wait for all the images to load and mouse over the "spin me" text

Quote:
PS: you should do your animations in Flash, not import them frame by frame
Typically I agree, especially if your animation can be vector. However, there are some things that Flash just can't do when it comes to animation. Good 3D with reflections, motion frame blending, motion tracking, etc just aren't possible with Flash's animation engine and you need to find an alternative.

@BenBob: You might actually want to consider using video for your animations. It will pose its own set of difficulties, but its going to be easier to load/que etc and it might be less processor intensive at run time depending on how large you need the images to be.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 2 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.