A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 41

Thread: Control loading speed with ActionScript

Hybrid View

  1. #1
    Member
    Join Date
    Jul 2010
    Posts
    61

    Control loading speed with ActionScript

    First please check the attached fla file. I have a shape tween loading, and an "Increase Speed" button.
    I want to when i click the button, the tween become faster. So i think i should make my tween with AS or something else. how to do that? and how to make that button a speed gainer.
    What's the solution?
    Attached Files Attached Files
    Professional WebDesigner_HTML, CSS, JS, PHP

  2. #2
    Member
    Join Date
    Jul 2010
    Posts
    61
    I don't know a lot about AS, and I need your helps. Please give me an answer.
    Professional WebDesigner_HTML, CSS, JS, PHP

  3. #3
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Remove the long Shape Tween inside your movieclip, when you only have 1 Frame left, click on the bar, open Properties Panel (CTRL+F3), and change its X position (which should be at that point, -5) to 0, to make its most Left-side part be on the registration point. Get out of the movieclip, repoisition the Bar movieclip as needed, click on it once, open Properties Panel (CTRL+F3), give it an Instance Name (in the Instance Name labeled text field) of for example, bar_mc. Click on your button once, give it an instance name of, for example, my_btn. Select your Border around the bar, convert it to a Movieclip, and give it an instance name of, bar_border. Click on your Frame, open Actions Panel (F9), and type this in there:

    Actionscript Code:
    speed = 1; // starting speed
    increaseSpeed = 1; // by how much the speed should be increased per click

    onEnterFrame = function(){
        if(bar_mc._width < bar_border._width){
            bar_mc._width += speed;
        } else {
            bar_mc._width = bar_border._width-2;
            delete onEnterFrame;
        }
    }

    my_btn.onPress = function(){
        speed += increaseSpeed;
    }

    DOWNLOAD FIXED FLA

    It basically tells Flash to keep extending the bar's width as long as its width is smaller than the width of the border, otherwise, end the increasing of the bar.

    Hope this works
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  4. #4
    Member
    Join Date
    Jul 2010
    Posts
    61
    O, Thanks a lot man! I understood the process, that worked great. Can you please tell me how I can tell the Flash to reset the bar after click on the button, and start it with the new speed? That means I want my bar to start from the start position after clicking the button. Thanks.
    Professional WebDesigner_HTML, CSS, JS, PHP

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Sure, just replace your code with this (change highlighted in red):

    Code:
    speed = 1; // starting speed
    increaseSpeed = 1; // by how much the speed should be increased per click
    
    onEnterFrame = function(){
        if(bar_mc._width < bar_border._width){
            bar_mc._width += speed;
        } else {
            bar_mc._width = bar_border._width-2;
            delete onEnterFrame;
        }
    }
    
    my_btn.onPress = function(){
        bar_mc._width = 0;
        speed += increaseSpeed;
    }
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  6. #6
    Member
    Join Date
    Jul 2010
    Posts
    61
    Thanks a lot! That worked great too. I'm making a flash game. May I ask my other questions here?

    I have a "on (press) {...}" function for my submit button. How I can add "keyPress "<Enter>"" to it?
    Also how to add that to "my_btn.onPress = function () {"
    I want my button to work with click and Enter key pressing. How to do that?
    Thanks.

  7. #7
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    First one is easy:

    Actionscript Code:
    on(press, keypress"<ENTER>"){
        // do something
    }

    while the second one is on a whole different level, which requires you to add a listener:

    Actionscript Code:
    keyListener = new Object();
    keyListener.onKeyDown = function(){
        if(Key.isDown(Key.ENTER)){
            // same code goes here as in "my_btn.onPress = function () {"
        }
    }
    Key.addListener(keyListener);

    Hope this helps despite its complexity
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  8. #8
    Member
    Join Date
    Jul 2010
    Posts
    61
    Thanks again! I made my buttons altogether, so I don't need the second one, and I'm free to understand that complexity! The first one helps me enough.
    There is another question: How to make something like a variable to store a process in it for use after on(press){}. For example:
    I want all of my buttons to do this works after clicking on them:
    Actionscript Code:
    score=score+10;
            level=level+1;
            animation.gotoAndPlay(1);
            loading.nextFrame();
            bar_mc._width = 0;
            password.text="";
    So should I write this scripts after all my on(press){...} functions or I can store them in a variable for example and use it after on(press){..}?
    Thanks!
    Last edited by farzadbayan; 03-21-2012 at 08:46 AM.

  9. #9
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    You can make a Function, and call it in all the buttons to simplify your work. Simply on your Frame Actions, make a function:

    Actionscript Code:
    function btnClick(){
        score=score+10;
        level=level+1;
        animation.gotoAndPlay(1);
        loading.nextFrame();
        bar_mc._width = 0;
        password.text="";
    }

    Then, in your button, just type, btnClick(); to call your function, for example:

    Actionscript Code:
    on(press){
        // some code here
        btnClick();
    }

    Hope this helps

    Tutorials to Read:
    Functions
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  10. #10
    Member
    Join Date
    Jul 2010
    Posts
    61
    Yea, That's what I wont! Thanks.
    My game programming is almost done, just there is one important part that I need your help to do:
    First please download my attachments. I made two files. One is the fla source, that explained the problem, and another is an animation of what I want. Please ask me, if you couldn't understand my problem from those files.
    I will become happy if you show me the solution.
    Thanks so much.
    Attached Files Attached Files

  11. #11
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Something like THIS?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  12. #12
    Member
    Join Date
    Jul 2010
    Posts
    61
    Yup, it's very nice and clean. But there is one problem: This burn the bar just once. I want to repeat this process for each click.
    That means for the second click, if:
    (fast_border._width - fast_bar._width) < main_bar, then the main bar will start from the burned area. (Now it's fine)
    But, if the (fast_border._width - fast_bar._width) > main_bar, then the main bar will burn more.
    Thanks for your kindly helps!
    Last edited by farzadbayan; 03-23-2012 at 04:20 AM.

  13. #13
    Member
    Join Date
    Jul 2010
    Posts
    61
    Also it have another problem: The burned bar (burned_mc) have a fixed width. As you know it shouldn't. Can you please help me to fix these problems?

  14. #14
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Not fixed width, then how long should it be? This is getting really complicated
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  15. #15
    Member
    Join Date
    Jul 2010
    Posts
    61
    Its long should be equal to:

    main_bar._width - (fast_border._width - fast_bar._width)
    (if it is > 0)

    I know it is complicated, but I think you can help
    Did you understand completely what I want?

  16. #16
    Member
    Join Date
    Jul 2010
    Posts
    61
    Is there somebody to help me please?

  17. #17
    Member
    Join Date
    Jul 2010
    Posts
    61
    Hey friends, I really need your helps. I know there are people in this forum, that can help me. Hoo Hoo, I haven't much time to make this game. So please.

  18. #18
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  19. #19
    Member
    Join Date
    Jul 2010
    Posts
    61
    You are really awesome! It is exactly what I wont! That helped me to continue my game =)
    I don't know, can the reduction occur with animation? Take a look at my attachment please. Can you do it? (at this time, the player can't understand what happened, with a simple animation, everything will be intelligible)
    Attached Files Attached Files

  20. #20
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    huh? Didn't really understand from the animation. Has the burned part been switched to Fast Loading?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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