+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 15 of 41

Thread: How to's

  1. #1
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40

    How to's

    I posted one already, but I think I may be posting more, and don't want to clog the forum with repeating "How to: ____" threads. I have been working hard with Flash MX, more specifically the Actionscript part, for a while, and I will try to answer the common questions I have encountered. If the mod's and admin don't mind, I would like to extend my services here (for free of course) and explain how to do somethin in Flash. I'll get the ball rollin'!

    1 frame Bar Preloader with Percentage Text

    I Can't tell you how many times I have come across this in other forums. Pretty easy once you get the hang of the coding.
    • 1. Make a movieclip with a rectangle. Make sure the "registration point" is on the far left.
    • 2. Once the rectangle is made into a movieclip, it should look like this:
      _______________________________
      |
      |
      +
      |
      |______________________________
      The + sign is the registration point

      If it doesn't line up properly, I apologize.



      Now, return to the main timeline, and open the actionscript editor. Click on the movieclip and add the code (in the panel):
      Code:
      
      onClipEvent (enterFrame) {
      	bytesL = _root.getBytesLoaded();
      	bytesT = _root.getBytesTotal();
      	perc = Math.round((bytesL/bytesT)*100);
               _root.percent.text=perc+"%"
      	this._xscale = perc;
      	_root.name._alpha=perc
      	if(_root.percent.text=="100%){
      		_root.play()
      		delete this.onEnterFrame
      	}
      }
      

    • Now, somewhere on the main timeline (not inside the movieclip), make a Dynamic Text Box with the Instance Name of "percent".

    This will make a few variables based on the total bytes and loaded bytes of the .swf, and then round that number, add a percent sign, and put it into the dynamic textbox named "percent".

    All done!

  2. #2
    Full Member MG315 is on a distinguished road
    Join Date
    Jan 2004
    Location
    Houston, TX
    Posts
    16
    only thing i disagree with is this part

    PHP Code:
    if(_root.percent.text=="100%){ 
    why compare it to a text field? just compare it to the original variable, perc. makes it much less confusing. also i like to add a small buffer after its loaded but before it starts playing. something like this

    PHP Code:
    lBytes this.getBytesLoaded();
    tBytes this.getBytesTotal();
    percentLoaded Math.floor((lBytes/tBytes)*100);
    loader.bar._xscale percentLoaded;
    if (
    lBytes>=tBytes && tBytes>0) {
        if (
    count>=2) {
            
    gotoAndPlay("main");
        } else {
            
    count++;
            
    gotoAndPlay("preloader");
        }
    } else {
        
    gotoAndPlay("preloader");

    keyframe on frame 1 of labels layer, with label of preloader. keyframe on frame 3 of labels layer with label of main and keyframe on frame 2 of actions layer with the above code.

  3. #3
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40
    Agreed. For some reason, it just doesn't work when I compare. I've tried:
    PHP Code:
    if(per==100){ 
    And every variation of it. Ack, I dunno. Such a small and trivial problem.

    As for your buffer, it works, but is a bit confusing for the newbies. "count++"? Both you and I know, but for those starting out may be more than needed. Usually I just have the bar fade out so it is more visually friendly, and some time to "settle" or whatnot before the movie begins.

    Thanks MG.

    -Steve

  4. #4
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40

    Elasticity

    This is a fun one. Not usually seen in the real world, but a fun effect nonetheless. Uses some math.

    On any Movieclip:
    PHP Code:
    onClipEvent (load) {
        
    // inertia relates to the quantity of energy that 
        // the spring will carry
        // inertia = 1 would mean that the spring doesn't 
        // loose any energy, and that it will oscillate
        // forever
        
    inertia 0.9;
        
    // k relates to the spring, and how "hard" it will be.
        // The higher k the faster the mass will come back.
        
    0.1;
    }
    onClipEvent (enterFrame) {
        
    // We calculate the distance to the mouse
        
    = -this._x+_root._xmouse;
        
    = -this._y+_root._ymouse;
        
    //We calculate the amount by which the mass will to move
        
    xp xp*inertia+x*k;
        
    yp yp*inertia+y*k;
        
    //We move it
        
    _x += xp;
        
    _y += yp;

    On MX04, you have to predefine what xp is, and that can be confusing at times. In Flash 6, xp and yp are jsut added onto each other as the FPS goes on. So the load event in MX04 would look like:
    PHP Code:
    onClipEvent (load) {
        
    inertia 0.9;
        
    0.1;
        
    xp=0
        yp
    =0

    Now, this can be modified to make the MC move as a menu item, button, or anything else. It doesn't have to be limited to the mouse. For example, this:
    PHP Code:
    onClipEvent (load) {
        
    _x 0
        _y 
    18;
        
    inertia 0.92;
        
    0.2;
    }
    onClipEvent (enterFrame) {
        
    = -this._x+160;
        
    //We calculate the amount by which the mass will to move
        
    xp xp*inertia+x*k/3;
        
    //We move it
        
    _x += xp;
        if (
    Math.abs(xp<.4)) {
            
    delete this.onEnterFrame;
        }

    ...looks confusing, but is a nice, light effect.

    Feel free to ask questions! I know there are some!

    -Steve

  5. #5

  6. #6
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40
    As far as I know, there's only one way to do this. I didn't plagarize (sp?), if that is what you are hinting...

  7. #7
    Full Member MG315 is on a distinguished road
    Join Date
    Jan 2004
    Location
    Houston, TX
    Posts
    16
    i'm not saying that, i just provided a link that had a little more explanation in it

  8. #8
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40

    Masking Dynamic Text

    I have had the displeasure of using dynamic text in MovieClips that are masked. The only way around it is to embed the font (see attached image). If you don't embed the fonts, they won't show up in the masked area.

    When you do, however, the text is very fuzzy and in my opinion, sometimes isn't worth using the method because it looks so bad!

    -Steve
    Attached Images Attached Images

  9. #9
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40

    Loading External Variables

    There are a few ways to go about this, but I have found this is all I need for simple functions.

    In Notepad (or something similar) type the variable name and the content with this format:
    Code:
    &varName=value
    The & character tells Flash that this is the beginning of a new variable. the varName is the name of the variable. Can be anything except a number or a name with spaces. value is what you want it to contain. No quotes are necessary, can have spaces, etc. Save the file as "variables.txt"

    In Flash, on the timeline, have:
    Code:
    loadVariablesNum("variables.txt", 100);
    This loads and stores the variables in that text document to level 100. That number can be anything

    Now that everything is loaded, lets do something with it. Lets say you want a few different stories on button clicks. In the notepad, write this:
    Code:
    &story1=Goldylocks
    &story2=Little Red Riding Hood
    &story3=The 3 Little Bears
    Make a textbox on the timeline with the instance name of "textbox". Then make three buttons. On button one, have:
    Code:
    on(release){
    _root.textbox.text=_level100.story1
    }
    This will make the textbox show "Goldylocks" when you press the button. Repeat this for each of the other buttons and presto!

    -Steve

  10. #10
    Full Member MG315 is on a distinguished road
    Join Date
    Jan 2004
    Location
    Houston, TX
    Posts
    16
    yeah that no dynamic text with masks thing really messed me up. i probably spent 4 days trying to get it to work when i finally gave up and stuck with static text. i was trying to do it with this site i recently did for a client:

    www.williampear.com

    go to a page like about us and you'll see how the text is masked. i guess when its time to make the html version we'll just need to make changes to both instead of a single database like originally planned.

  11. #11
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40
    Yea, it really stinks that Macromedia hasn't fixed it yet

  12. #12
    Account Disabled Optigamer is on a distinguished road
    Join Date
    Jun 2004
    Location
    Newnan Georgia
    Posts
    107
    Wow, You really know your stuff. I'm still learning Flash and that is all greek to me.

  13. #13
    Active Member Fabolous05 is on a distinguished road
    Join Date
    Jun 2004
    Location
    Surrey, BC
    Posts
    151
    I know how to make very very basic flash movies but I don't know jack about the code, nor did I even know about the code until this point
    Fabo@VolantaStudios.com
    Head Designer
    Volantą Studios

  14. #14
    Full Member cdingman is on a distinguished road
    Join Date
    Jun 2004
    Location
    South Amboy NJ
    Posts
    96
    Originally posted by Fabolous05
    I know how to make very very basic flash movies but I don't know jack about the code, nor did I even know about the code until this point
    Same here Fab - I can make a simple flash movie but I didnt know there was any kind of code that went with it...
    Chris Dingman
    Webmaster
    <A HREF="http://www.cabarettheatre.org" target="_blank">Cabaret Theatre</A><BR>
    <A HREF="http://www.twinlightdesigns.com" target="_blank">Twinlight Designs</A>

  15. #15
    Full Member bling is on a distinguished road
    Join Date
    Jan 2008
    Posts
    10
    exactly what i was looking for. thank you

+ Reply to Thread
Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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