A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [F8] Buttons & ActionScript

  1. #1
    Junior Member
    Join Date
    Oct 2006
    Posts
    25

    [F8] Buttons & ActionScript

    I'm creating an interactive flash animation in which there are five buttons (numbered 1 - 5). The idea is that when each button is pressed a corresponding number of incense sticks appears to the left of them, so when 1 is pressed 1 stick of incense appears, when 2 is pressed 2 are supposed to appear, etc. These sticks can be dragged and dropped by whoever's viewing the animation at the feet of a statue/altar, and when each stick of incense is placed in an incense holder there an aura appears around the statue, and it grows bigger as more sticks of incense are placed there.

    I have it set up so that when the first button is pressed it directs the animation to frame 31 (the first 30 frames show nothing happening and have stop actions placed on them) in which the first animated incense stick appears and then the aura appears after a delay (since I haven't figured out how to "trigger" it to appear when the incense stick is placed on the altar yet, I just leave a lapse of time for someone to place the stick in).

    I'm trying to make the rest of the buttons work now, and so for button two I'm using the following code: on (release) {gotoAndPlay(209);

    }

    to try and get the animation to start at frame 209, where I've placed a second incense stick. The thing is that when I click on button 2 only the first stick appears and it loops back the original aura tween without a delay (since 208 is the last frame of the animation button 1 leads to), so I'm not sure if this method really works or if I'm just not doing it correctly. Is there some way I can rig this, like for instance by creating a seperate scene for the button to lead to, to make it work properly?

    I also don't want for the first button's animation to lead into the second one's automatically, but I can't use stop actions at the end of the first button's animation because it stops the aura tween from looping itself, so that creates another problem.

    But I'd also like to create some sort of "trigger", if it's possible, so that when someone places the incense stick in the holder the aura animation starts up from that rather than being on the main timeline with a delay, but I don't know how to accomplish that. I was thinking I could make an invisible button and use a rollover code or something.

    This is only my second flash animation so it's all just kind of confusing for me, so I'm sorry if I couldn't communicate the problem efficiently. I'd like to upload the file here so that there's an example to view but it's too big (1.77 mb), so if someone would like for me to e-mail it to them let me know.

    Any help would be much appreciated,
    Thanks,
    Art

  2. #2
    Junior Member
    Join Date
    Sep 2006
    Posts
    12
    Click on your frames you want to go to and at the bottom, label them.

    Then on buttons

    on (release) {
    gotoAndPlay (frame);
    }

    Hopefully that works. Case sensitive xD

  3. #3
    Senior Member
    Join Date
    Oct 2003
    Posts
    1,354
    Pretty advanced for your second project, but worthwhile learning.

    To post a large file, you can use yousendit.com, just email the file to yourself, then post the link they mail to you on here.

    From the file size, it sounds like you did all the graphics first. I tend to use small clips and work out the actions first, then build the real graphics once I know how things will work. That said, doing the graphics first may create inspiration for you to finish the code part, so it's all good.

    It's a little confusing on how you are trying to do things. And in flash there are usually a dozen ways to get something accomplished. You will most likely want to learn how to duplicate movieClips, attach movieClips, learn how to link a clip in the library, drag and drop, create functions, and how to do a hitTest. A hit test will check if one movieClip is on top of another.

    Attached is an example I made up...
    You will see that everything has one frame, except for the fireMC. (The power of actionscript!!)
    Rather then waste time teaching you something you already know. take a look at it, and let me know what you dont understand.

    You will see alot of lines that look like this...
    Code:
    _root["stack"+i]._y = 100
    This is sometimes refered to as 'array syntaxing'
    It is a way to dynamically build up a path in your code.
    Say you have several movieclips called stack1, stack2, & stack3
    you could refer to them by name..
    Code:
    stack1._y = 100;
    But sometimes, when you are writing the code, you will not know the name that will be called so you use array syntaxing. You build up the name using static text (those in quotes) and variables and you put them inside of brackets. Notice that there is no dot in front of the bracket and there is a dot behind the bracket.

    Also, please see my previous post concerning frame and movieClip based actions...
    http://board.flashkit.com/board/show...ht=frame+based

  4. #4
    Junior Member
    Join Date
    Oct 2006
    Posts
    25
    Creepy: Thanks, I will try your method, but one question: how do I label frames?

    Dallas: Yes, it sort of just fell into my lap and it's based on ideas more than it is on my experience with flash so I'm having to try and gather information to figure out how to make it work.

    I did a rough draft first with some simple buttons, and then I added the graphics so that I could figure out a color scheme and how to balance things out, roughly, and now I'm trying to figure out all the code. It just kind of came about in that order I guess.

    I looked at your example and it's similar in basic principle (in my case animated incense appears and I put it in a certain spot to make an animated aura get bigger), but I really couldn't make much out of most of the code you used. I basically only understand the button actions and the gotoAndStop action you used, and the only other action I'm really familiar with is onMouseDown and onMouseUp for drag and drop.

    So it's all greek to me, but stuff I'd like to figure out if you can give me any further information.

    Thanks

  5. #5
    Junior Member
    Join Date
    Sep 2006
    Posts
    12
    Click on your keyframe you want to goto, and near the bottom it should say "Properties". If it doesn't press Ctrl + F3. Then where it says "Frame" under it will be a box saying "Frame label"
    Then use it in the

    gotoAndPlay (framelabelhere);

    code

  6. #6
    Back to FK Boards!
    Join Date
    Apr 2006
    Location
    Troy
    Posts
    234
    ok i decided to make you a quick animation for the basic outline and actionscript needed. but the drawings suck but whatever.

    the only thing is that the holders dont work because i dont really know how to do that aura thing.

    but i added an X button to make the incense sticks reset!

    i spelled incense wrong too!

    but hope that helps a little. bye bye
    Email: Jacktown012@aim.com
    AIM: jacktown012
    MSN: megafire987@hotmail.com

  7. #7
    Back to FK Boards!
    Join Date
    Apr 2006
    Location
    Troy
    Posts
    234
    haha i forgot the .fla!


    here it is.
    Last edited by Dark Cloud; 08-16-2007 at 11:51 AM.
    Email: Jacktown012@aim.com
    AIM: jacktown012
    MSN: megafire987@hotmail.com

  8. #8
    Junior Member
    Join Date
    Oct 2006
    Posts
    25
    you are ****ing awesome

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center