A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: edit var from main time line in a movie clip

  1. #1
    Junior Member
    Join Date
    Oct 2008
    Posts
    4

    edit var from main time line in a movie clip

    I'm creating a balloon game where the user is supposed to hit balloons with a needle in order to make them disappear. (have a look at the swf-file).

    In the main time line I have created the variable 'lifes' with a value of 4. My intention is that every time the user miss a balloon, he loses a life.

    The balloons is a looped movieclip, and I would assume that the best solution would be to put something like this:

    life = life-1;

    in the end of the balloon movieclip, but the variable does not seem to exist inside the movieclip. I cant even trace it...

    Here is links to my .swf and my .fla

    .swf
    http://www.irritasjon.com/unsw/flash..._blaster_5.swf

    .fla
    http://www.irritasjon.com/unsw/flash..._blaster_5.fla

  2. #2
    Senior Member
    Join Date
    Apr 2008
    Location
    Nottingham, UK
    Posts
    348
    Hey,

    In AS3 you're actually supposed to do everything in the main timeline or document class.

    one example:

    Code:
    //document class
    balloon.lifes -= 1;
    balloon.someFunction();
    this would mean that you can store global variables on the main timeline or in your document class, and access your class/movieclip variables externally.

    Dan

  3. #3
    Member
    Join Date
    Dec 2004
    Posts
    68
    Try this code:

    MovieClip(root).life--;



    in your movieclip time line.

  4. #4
    Junior Member
    Join Date
    Oct 2008
    Posts
    4
    Quote Originally Posted by dan_hin
    Hey,

    In AS3 you're actually supposed to do everything in the main timeline or document class.

    one example:

    Code:
    //document class
    balloon.lifes -= 1;
    balloon.someFunction();
    this would mean that you can store global variables on the main timeline or in your document class, and access your class/movieclip variables externally.

    Dan

    Hmm.. Sorry, I'm new to actionscript. I dont see how this can help me. Could you please explain a little bit more?

  5. #5
    Junior Member
    Join Date
    Oct 2008
    Posts
    4
    I still cant make this work....

  6. #6
    Member
    Join Date
    Dec 2004
    Posts
    68
    I tried to download your fla, but the link was broken.

    Keeping all you AS on the main time line is not a bad idea.

    You could check which frame your balloon mc is on by altering the following script to suit your script:

    if(balloon_mc.currentFrame == 19 //or whatever the last frame is){
    life--;
    }

    Hope this helps.

  7. #7
    Junior Member
    Join Date
    Oct 2008
    Posts
    4
    Quote Originally Posted by friedegg3
    I tried to download your fla, but the link was broken.

    Keeping all you AS on the main time line is not a bad idea.

    You could check which frame your balloon mc is on by altering the following script to suit your script:

    if(balloon_mc.currentFrame == 19 //or whatever the last frame is){
    life--;
    }

    Hope this helps.

    oh sorry about the faulty links. I have placed it here: http://home.no/baboon/flash/

    Should be working.

    I tried to use the code in your post. It worked well with a movieclip, but I'm having trouble as the balloons flying by are array/children-balloons..

    hmm..

  8. #8
    Junior Member
    Join Date
    Oct 2008
    Posts
    4
    and one more thing. I would like the balloons to appear more and more often as a way of making the game more difficult, but I cant manage to do it. I would assume there is an easy solution. Just adding something to the loop somewhere...

  9. #9
    Member
    Join Date
    Dec 2004
    Posts
    68
    I’ve downloaded your fla and have some comments:

    First your script is unorganized. For example: You have script for the mountains on lines 5, 6 and 8, then again on line 20 and 21, and again on line 46. I like to keep my script ‘tidy’, so that if I have a problem with the mountains, I don’t have to scroll through lines of unrelated script to find the one or two lines I’m looking for. If you spend a few minutes rearranging the script, you might be able to see what problems you have.

    You have the balloon mcs as animated movie clips. I would have the balloons rise using action script.

    There is a missing bracket or parentheses somewhere (or maybe reversed). I was only able to glance through quickly but something just doesn’t look/work right. I'm getting output errors.

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