A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: What I think is a simple Actionscript Question

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    3

    Talking What I think is a simple Actionscript Question

    I am creating an Flash movie where I click on items on the screen. Once I've clicked on all the items I want to have the movie continue. I have the items created and each have a different name. I have the actionscript creating a variable:

    X = 0;

    I assume I can increase this variable each time I click one of the items and then when the variable hits a specific number it runs the rest of the movie.

    If I however am unsure of how to write this proprerly. Or if this is going to be the best way to accomplish what I'm trying to do.

    Any help on this would be appreciated.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You haven't given us much to go on regarding what you DO know how to do. Do you know how to set up event listeners?

    The basic scheme you outline is workable. It would look something like:
    Code:
    var X:int = 0; //notice the var, and type.  The line you had only assigns a value to an existing variable.
    
    for (var i:int = 0; i < items.length; i++){
      //I'm assuming you have your items in an array.  If you don't, you can do the inside of this loop for each item.
      items[i].addEventListener(MouseEvent.CLICK, clickCount);
    }
    
    function clickCount(event:MouseEvent):void{
      event.currentTarget.removeEventListener(MouseEvent.CLICK, clickCount); //make this item no longer responsive so they have to click each one.
      if (++X >= items.length){
        play();
      }
    }

  3. #3
    Junior Member
    Join Date
    Feb 2009
    Posts
    3
    Sorry, I was in a hurry and I should have been more specific.

    I have a flash movie. It currently has a women holding 4 balloons. Each ballon is a Movie Clip. I have eventlisteners in the script that when you click on each of the balloons it runs the movie clip of the balloon popping. Each ballon is a seperate MC and has a seperate instance name. I can click any balloon at any point and it will pop. What I want to occur is that once the 4th balloon, whichever that balloon is, pops I want the flash movie to jump to the next frame a play the rest of the movie. My assumption is that I can create a variable such as var x = 0; which creates my initial variable value. I want to create an event on each of the balloons that increases that value by 1. So if I click on ballon1_mc it increases X by 1. Once the variable X reaches 4, I want to have a statement that says "if x = 4 goto and play" (I know that isn't the code, just giving a simplified example). I am a not master coder, more of a part time coder, so I understand the concepts but haven't mastered them.

    I hope this makes better sense of what I need. And what level I'm at to try and get this working.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You already have an event listener on the clips. Just put your X += 1 and if test in that same function. It should work.

  5. #5
    Junior Member
    Join Date
    Feb 2009
    Posts
    3
    that worked perfectly. Thanks

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