Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 4 of 4
  1. #1
    Veteran Enthusiast LeadingManNigel's Avatar


    Join Date
    May 2005
    Location
    New York City
    Posts
    6,213

    [Mini Tute]Basic Dynamic Bar(s)

    This tutorial is for ActionScript 2
    Made in CS3
    A dynamic bar is simply a bar whose properties are changed in real time while the Flash is being played. It is mostly used for HP Bars and Preloaders.
    1. First open flash, I hope you know how to do this O_o

    2. Select the rectangle tool(Short Cut Key:'r')

    3. Draw a rectangle, size does not matter just don't over do it :P

    3a. I suggest you make the fill a diffrent color from the outline, not necessary but it
    makes seeing the bar in action a bit easier.

    Figure 1.
    [img]http://**********.com/img/1237053866.png[/img]

    4. Now select the fill
    Figure 2.
    [img]http://**********.com/img/1237053978.png[/img]

    5. Hit 'F8' and convert the fill to a movieclip. Name dosent matter.
    Please make sure you set the bars registration to the left(Shown in Figure 3) otherwise my method wont work.
    Figure 3.
    [img]http://**********.com/img/1237054157.png[/img]

    You may have notice that the bar fill is above the outline, to fix this just 'right-click' the bar fill movieclip and select 'Distribute to layers'. This will put the bar fill on a new layer, just move the layer down below the outline(If it isn't already set below the outline)

    6. Select the bar fill and open up the properties window.(Short cut key:'Ctrl+F3)
    Name the bar fill's instance name anything your heart desires. For comedic purposes I have named mine:
    Figure 4.
    [img]http://**********.com/img/1237054534.png[/img]

    7. Ok, now here comes the fun part; CODING Its actually very simple even an AS(ActionScript) Noobie can understand. Make a new layer called:"AS" and lock it.
    Select the new layer and open up the actions panel.(Short cut key:'F9')
    Heres the code along with explainations:
    Figure 5.
    Code:
    stop(); //Stops the Movie
    var Currenthp:Number = 1000;//Sets the variable for the users current hp
    var Maxhp:Number = 1000;//^For maxhp
    IfULookHereUrNoob.onEnterFrame = function() {//Simple every time the movie go thru a frame it executes the block of code. Im running at 28 fps
    	this._width = Currenthp/Maxhp*190;// Sets the barfills based on the current hp, becuase its minor than 0 we multiply the bars with by its starting width(in my case 190)
    	if (Currenthp>Maxhp) {// This was just added because my bar is based on a players hp so if that player heals beyond my max hp it resets it to the max hp
    		Currenthp = Maxhp;
    	}
    };
    I hope this has help you in anyway possible
    Now help me by pointing out any errors I may have made. Thanks for reading.
    Press here to see bar in action, Green button reduces hp, grey increases.

  2. #2
    Senior Member TheCactusSandwich's Avatar
    Join Date
    Oct 2008
    Location
    2Fort
    Posts
    312

    Re: [Mini Tute]Basic Dynamic Bar(s)

    (i know this a bump but im asking some questions)
    thanks very much xinq

    just one question
    how would you get it to play after its loaded(preloader)?


  3. #3
    Veteran Enthusiast LeadingManNigel's Avatar


    Join Date
    May 2005
    Location
    New York City
    Posts
    6,213

    Re: [Mini Tute]Basic Dynamic Bar(s)

    Depends, do you want it to autoplay then use this
    Code:
    if (_root.getBytesLoaded() == _root.getBytesTotal()) {
    		gotoAndPlay(insert frame number here);
    or if you want a play button then:
    Code:
    if (_root.getBytesLoaded() == _root.getBytesTotal()) {
    		play button instance name here._visible = true;
    	} else {
    		play button instance name here._visible = false;
    	}
    There are other tutorials on button making around here.
    Don't forget to make sure the 'if's are properly closed.

    Tutorials can be bumped only if you have a question.

  4. #4
    Senior Member TheCactusSandwich's Avatar
    Join Date
    Oct 2008
    Location
    2Fort
    Posts
    312

    Re: [Mini Tute]Basic Dynamic Bar(s)

    THANKS SO MUCH.....

    wow.. this was actually easier than i expected from previous experiences with Flash...
    xinq... you rock!!


 

Posting Permissions

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