A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Pop up number? Flash RPG

  1. #1
    Senior Member
    Join Date
    Mar 2005
    Location
    U.S.A . VA.
    Posts
    108

    Pop up number? Flash RPG

    I am able to display a certain amount of damage that was done during an attack. But what if I wanted the numbers in a better font? Or some sort of animation? Could this be done with a movie clip? surely I wouldn't have to make 1 movie clip for every possible numerical outcome of the damage right?

    Here is the current code I use to display damage ((For some reason I named the variable "monies" as this experiment/educational flash file started out as a bar tender clicky thing))



    code:
    _root.popupNumber=function(x:Number,y:Number,value  :Number){
    var mc=_root.createEmptyMovieClip("temp",_root.getNext HighestDepth());
    mc._x=x;
    mc._y=y;
    mc.spd=1;
    fmt=new TextFormat();
    fmt.font = "monies";
    fmt.color = 0x3399FF;
    fmt.size = 96
    mc.createTextField("txt", mc.getNextHighestDepth(), 0, 0, 100, 100);
    mc.txt.autoSize="center";
    mc.txt.embedFonts=true;
    mc.txt.selectable=false;
    mc.txt.text=value;
    mc.txt.setTextFormat(fmt);
    mc.onEnterFrame=function(){
    this.txt._x=-this.txt._width/2;
    this.txt._y=-this.txt._height/2
    this._alpha-=this.spd;
    this.spd+=1;
    if(this._alpha<=0)this.removeMovieClip("temp");



    Thanks anyone who read this far! :P
    Last edited by Ecuder; 10-29-2012 at 04:56 AM.
    How can you say so much, but say so little?

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    In that case, you better create the movieclip manually, then assign an instance name to it in the library, then in the properties/linkage panel check Export to first frame and Export for actionscript. Then
    PHP Code:
    _root.popupNumber=function(x:Number,y:Number,value  :Number){

     
    _root.attachMovie("YouMovieClipInstanceName""mc",_root.getNext  HighestDepth());[/B]

        
    mc._x=x;

        
    mc._y=y;

        
    mc.spd=1;

        
    fmt=new TextFormat();

        
    fmt.font "monies";

        
    fmt.color 0x3399FF;

        
    fmt.size 96

        mc
    .createTextField("txt"mc.getNextHighestDepth(), 00100100);

        
    mc.txt.autoSize="center";

        
    mc.txt.embedFonts=true;

        
    mc.txt.selectable=false;

        
    mc.txt.text=value;

        
    mc.txt.setTextFormat(fmt);

        
    mc.onEnterFrame=function(){

            
    this.txt._x=-this.txt._width/2;

            
    this.txt._y=-this.txt._height/2

            this
    ._alpha-=this.spd;

            
    this.spd+=1;

            if(
    this._alpha<=0)this.removeMovieClip("temp"); 
    Now that you attached your library's movieclip to the code, now you can animate your movieclip manually in the timeline and add effects to it and these effects will affect your dynamic textbox too.

    Hope that helps!
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    Senior Member
    Join Date
    Mar 2005
    Location
    U.S.A . VA.
    Posts
    108
    Still a little bit lost...

    So do I just make a blank MC? And export for action script in the first frame? Then Any time i use this MC and drag it around the stage it will display dynamic text inside of it?
    How can you say so much, but say so little?

  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Yes. Instead of creating the empty movieclip with actionscript, you create it "manually", so yo can animate it with tweens. Create one empty movieclip on the stage, then, inside of it create another one (the 1st one is the container, and the 2nd one is the one who will hold the dynamic textbox and you'll be able to animate it in the timeline of the first movieclip with tweens. If you want, I can make you an .fla so you can understand what i mean. Cheers
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  6. #6
    Senior Member
    Join Date
    Mar 2005
    Location
    U.S.A . VA.
    Posts
    108
    Ok! I understand the Container idea. But having trouble applying the code?

    The code I posted is in my 1st frame. Does this code need to be tweakd to use this "movie clip exported for action" thing? Here is the simple code I use on my "attack button" (( or my buy a drink button lol whatever you wana call it))

    PHP Code:
    on (release) { var wv:Number random(100)+7;   
    money -= wv
    _root.popupNumber(1,-2,wv);
    var 
    wv:Number = +7;   
    gotoAndPlay (2);

    Where would I place the code you posted? 1st frame or button? Or do both the codes need to be tweaked a bit to make this much better system work? Thanks!
    Last edited by Ecuder; 11-01-2012 at 11:58 PM. Reason: Because sweet dreams are made of me, who are you to disagree?
    How can you say so much, but say so little?

  7. #7
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    It's better to put all the script on the first frame. The thing is, instead of creating the "emptyMovieClp" container with script you create it on the library (the container), and inside of that movieclip, create another (the one to be animated), so you keep using your script, but tweak it a little to not use the "emptyMovieClip" and instead use _root.attachMovie("MyLibraryMovieClipName", "name2");

    Then, enter inside the MyLibraryMovieClipName, and then you animate the insider movieclip with the Dynamic textbox directly on the timeline.

    That will do this:
    1-MyLibraryMovieClipName is attached where and when your script says
    2-The MyLibraryMovieClipNamemovieclip has a movieclip inside, that will be animated with the dynamic textbox
    3-You call your dynamic textbox on the root timeline on yourscript and change its parameters
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  8. #8
    Senior Member
    Join Date
    Mar 2005
    Location
    U.S.A . VA.
    Posts
    108
    I will try this when i get home from work today,

    You aslo made a demo .fla is it possible i can download it and look at it?
    How can you say so much, but say so little?

  9. #9
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    What Flash version do you have ?
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  10. #10
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  11. #11
    Senior Member
    Join Date
    Mar 2005
    Location
    U.S.A . VA.
    Posts
    108
    Flash 8 - sorry.

    Cant open those. Sorry to be so much trouble I really appreciate what youve done so far
    How can you say so much, but say so little?

  12. #12
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    This is my script on frame 1:
    PHP Code:
    var closed=true;
    function DO(){
        if(
    closed==false){
            
        }
        else {
         var 
    barName:MovieClip =
     
    _root.attachMovie("mainMC""mainMC",_root.getNextHighestDepth(), {_x:160,  _y:100});
    mainMC.mc.myTxt.text=myText.text;
    closed=closed=false;
    barName.bton.onPress=function(){
        
    barName.removeMovieClip();
            
    closed=true;
    }
        }

    }

    btn.onPress=function(){
        DO();
        
    }



    btn2.onPress=function(){
        
        
    mainMC.mc.myTxt.text=myText.text;
        

    Then on the stage I have the myText dynamic textbox, the btn (to create the popup) and the btn2(to change the popup movieclip dynamic textbox.


    At last, in the library I have the mainMC movieclip, inside of it i have 2 layers, on with another movieclip called mc that is animated there in the mainMC timeline with a tween and alpha/opacity, and the other with the dynamic texbox called myTxt
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  13. #13
    Senior Member
    Join Date
    Mar 2005
    Location
    U.S.A . VA.
    Posts
    108
    Ok Follow with my steps if I mess up?

    1. added your code to the 1st frame

    2. created a movie clip with a dynamic text box named "Damage float"

    3. Made the mc exported for as in the first frame

    4. Named the dynamic text to "DMG" instance name

    5. changed your codes "MainMC" quotes to "damage float quotes"


    However there seems to be some other lines in this code Im not understanding Or i think they are doing something different.

    My goal is: I click a button, and a random number pops up and subtracts from anther var. With this popped up number i tween it around the stage or whatever.

    Having the container MC i think we have accomplished the animation part. Im guessing i need to replace the mytext with "dmg"? not sure how many of the "my text"'s I actually need to replace xD
    How can you say so much, but say so little?

  14. #14
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok, i'm not focusing on the "random" thing, but the Movieclip animation.

    As I said at first, you can keep using your script, the difference is, instead of using create emptyMovieClip, you create the movieclip manually on the library (the container), then, inside of that movieclip you create another movieclip (the one that will be animated) and the dynamic textbox of that popup movieclip.

    My script is for if you created the popup window, and press the "X" , don't create more and more and more popup windows( thats the closed=true/false thing). So my script is only for showing the popup window animation purposes.

    So this is what you gonna do:

    remove the var mc=_root.createEmptyMovieClip("temp",_root.getNext HighestDepth());
    and replace with _root.attachMovieClip("Damage float", _root.getNext HighestDepth());

    and inside the Damage float movieclip, create another movieclip, that is the one you will animate on the Damage float timeline along with the dynamic textbox. Hope i'd had been clearest as possible.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  15. #15
    Registered User
    Join Date
    Oct 2012
    Location
    bangladesh
    Posts
    1
    when posting a code please explain a few key points of the code

  16. #16
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Hi rockyseo12

    If you really reed the whole thread, you will notice I explained my script very well. The only thing I did was replace var mc=_root.createEmptyMovieClip("temp",_root.getNext HighestDepth());
    with _root.attachMovieClip("Damage float", _root.getNext HighestDepth()); and i think I repeated it twice. I think I have explained myself very well, telling Ecuder many times, that if he want to animate his popup movieclip, he should create the movieclip manually (will act as a container) then inside of it create another movieclip (the one that will be animated along with the dynamic textbox) and thats all.
    Last edited by angelhdz; 11-03-2012 at 04:51 PM.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  17. #17
    Senior Member
    Join Date
    Mar 2005
    Location
    U.S.A . VA.
    Posts
    108
    Quote Originally Posted by angelhdz View Post
    Hi rockyseo12

    If you really reed the whole thread, you will notice I explained my script very well. The only thing I did was replace var mc=_root.createEmptyMovieClip("temp",_root.getNext HighestDepth());
    with _root.attachMovieClip("Damage float", _root.getNext HighestDepth()); and i think I repeated it twice. I think I have explained myself very well, telling Ecuder many times, that if he want to animate his popup movieclip, he should create the movieclip manually (will act as a container) then inside of it create another movieclip (the one that will be animated along with the dynamic textbox) and thats all.
    I think he saw this thread and was hoping to learn about making an rpg (post count)

    Anyways, everytime I try this I end up with this problem

    PHP Code:
     **Error** Scene=Scene 1layer=Layer 5frame=1:Line 8')' or ',' expected
         _root
    .attachMovieClip("Damage float"_root.getNext HighestDepth());

    **
    Error** Scene=Scene 1layer=Layer 5frame=1:Line 17Unexpected '}' encountered
         
    }

    Total ActionScript Errors2      Reported Errors
    I spent the best part of yesterday trying to move the } and the ) , around to make it work xD where did I misplace it

    PHP Code:
    var closed=true;
    function DO(){
        if(
    closed==false){
            
        }
        else {
         var 
    barName:MovieClip =
    _root.attachMovieClip("Damage float"_root.getNext HighestDepth());
    mainMC.mc.myTxt.text=myText.text;
    closed=closed=false;
    barName.bton.onPress=function(){
        
    barName.removeMovieClip();
            
    closed=true;
    }
        }

    }

    btn.onPress=function(){
        DO();
        
    }



    btn2.onPress=function(){
        
        
    mainMC.mc.myTxt.text=myText.text;
        

    How can you say so much, but say so little?

  18. #18
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    http://sofistica2.zzl.org/cool.html Look at this and tell me if this is what you need
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  19. #19
    Senior Member
    Join Date
    Mar 2005
    Location
    U.S.A . VA.
    Posts
    108
    Need that example saved in a flash 8 format xD

    Yes that is what im going for!
    How can you say so much, but say so little?

  20. #20
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok, let me download Flash 8 , so i can give it to you in that format (i have flash cs3, cs4, cs5, and cs6 , but Flash 8 hehe)
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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