Output 0# instead of just # in Flash CS4 AS3

Hi,
I was wondering if there is any way to get an number output always in a two digit number, for example time:
What my code does right now:
0:1
0:2
0:3
0:4
0:8
0:9
0:10
0:11
What I want my code to do:
0:01
0:02
0:03
0:04
0:08
0:09
0:10
0:11
Thank you for any help and tips!

First you have to determine if the number is less than 10, and if so, add a zero before it when you cast it as a String.
Take this number for example:
var myNumber:Number = 5;
First, you need to determine if the number is below 10
if (myNumber < 10)
And if so, you will have to cast your number from a number to a String with a zero in front.
var myString:String = "0" + String(myNumber);
I did this just last week to make an MP3 Player.
Here are two functions I used to convert the number (in this case, the milliseconds being played) into a time format:
function showTime(e:Number):String
    //e is in milliseconds
    var time:int = Math.round(e/1000); // time is now in seconds
    var hours:int = Math.floor(time/3600);
    var minutes:int = Math.floor((time - (hours * 3600))/60);
    var seconds:int = Math.floor(time - (hours*3600) - (minutes*60));
    var hoursText:String = convertToString(hours); // function - see below
    var minutesText:String = convertToString(minutes);
    var secondsText:String = convertToString(seconds);
    var showTime:String;
    if (hoursText == "00")
        showTime = minutesText + ":" + secondsText;
    else
        showTime = hoursText + ":" + minutesText + ":" + secondsText;
    return showTime;
    }showTime
function convertToString(e:int):String
    var returnString:String;
    if (e == 0)
        returnString = "00";
    else if (e < 10)
        returnString = "0" + String(e);
    else
        returnString = String(e);
    return returnString;
}//convertToString

Similar Messages

  • (Help) Using Input text in Flash CS4 AS3

    I am trying to take a user's input (His Name) and then greet the user on the next frame using the name he previously entered. I googled for 2days and was unable to find a way to do this on flash CS4 AS3, i guess because im very new to flash (only 2-3weeks )
    Any help would be greatly appreciated, and i am sorry if this was already answered in the forums.
    thanks for reading.

    If your interested... here's some general "rules of the road" that are basically courtesies...
    Don't post the same question in different forums (crossposting).  Folks that help don't like that because they can waste their time providing the same response someone else already offered elsewhere, or their helpful info gets no attention because the OP (original poster) got wrapped up in the discussion elsewhere and never went back to the other forums.  I saw one time where the OP suffered from doing this... the first person to respond in one forum said what they wanted couldn't be done, while my response in another forum showed them how to do it... but they accepted that it couldn't be done and never returned.
    Don't post in someone else's posting unless the exact same situation applies to you and it is a current posting.  It is a bit rude to step into someone else's posting just to get attention, which some people do... some with totally unrelated problems.  Or if your problem is even slightly different, it can end up confusing matters for all involved... trying to juggle helping two people where different solutions are needed.
    If you get one problem resolved and have another you want help with that does not involve the first, start a new posting.  People search these forums so it helps to have topics match the postings, which will not apply if mutliple topics get resolved under one title.  I recently saw one person tell someone to start a new posting even though they were following up to clarify something of the solution they received... that's wrong and is more likely someone with a case of points greed... as useless as points are, it happens.

  • How can I NOT let collision happen in Flash CS4(AS3)?

    I have been playing with collisions for quite a while, but cannot seem to get it just the way i want it to be.
    I made a new rectangle into a Movie Clip, with an instance name : "block_mc"
    I made a sphere into a Movie Clip, with an instance name : "ball_mc"
    I made the sphere(ball_mc) movable with the arrow keys.(see post:http://forums.adobe.com/thread/491457?tstart=0 )
    Now I wanted to try and make the sphere(ball_mc) stop moving so it wont hit the rectangle(block_mc), so that the rectangle(block_mc) would act like a solid object.
    Meaning the sphere(ball_mc) would not be able to touch the rectangle(block_mc). It would act like a wall.
    Now my problem is I don't know if there is a way of not letting objects collide?
    I tried the ".hitTestObject()" but that did not work for me.
    ~ Thanks for Help and Advice~

    I apologize, for this confusing long question, I simply ment to ask:
    Is there a way Flash CS4(AS3.0) will not let Objects on stage collide?
    ~Thank you for any Tips, Advice and Help~

  • Need help in screen capturing for flash CS4 AS3

    Hi, i need help!!!!!!!!!!!!!!!!!!!!!! URGENT!
    I am currently doing Augmented Reality.
    I got my marker to detect my model but my problem now is how to screen capture the content that is in swf.
    (As in capture the dae model shown in the comp not from webcam.)
    & also i just want to capture the swf window not the whole desktop.
    I read online, they say its impossible?
    Or is it possible to call screen capture function in javascript to flash CS4? (LIke external data)
    (Moreover, does anyone know how to detect multiple dae models with different markers?)
    Anyone can help??? Thanks in adv!!

    My current program (Flash CS4, AS3) only can capture what the webcam sees.
    How do i change it to screen capture (something like print screen) with my .DAE models?
    In the case, when i click on the capture button, it print screen.
    Here's part of the code that capture what the webcam sees.
    private function captureImage(e:MouseEvent):void
       bmd.draw(stage);
       bmp = new Bitmap(bmd);
       bmp.x = 140;
       bmp.y = 40;
       addChild(bmp);
       capture.visible = false;
       saveButton.visible = true;
       discardButton.visible = true;
    Really really need help! URGENT!
    Thanks!

  • Flash CS4/AS3 - How to use a preloader with FLVs?

    Somehow I've had a really hard time finding a straightforward forum answer or tutorial for this--maybe someone can help?
    I have an SWF file that references/loads an external FLV file (www.44designs.com/promo_video.php), but since the FLV file is about 9MB and can take time to load on a slower connection, I think a preloader (something simple like "LOADING...100%") would be a good idea as the FLV loads.
    Anyone have a simple way to do this??  I've had no success in finding what I need--just scripts for loading SWFs.  You can see an example of this on www.44designs.com where a preloader script I've got seems to be referencing the SWF (thus loading almost immediately) instead of the much larger external FLV.  Make sense?  I'm not super AS3 savvy, but I can follow logic and cut and paste

    Great info, thanks for the post!

  • Getting Information from ID3 tags from streamed mp3 files in Flash CS4 AS3.0

    Hi everyone:
    I have spend my whole day trying to find a good way to access ID3 tags in AS3.0; but didn't find anything helpful.
    In my project I am making a sound object and assigning it a URL:
    Then I stream the sound into a sound channel:
    var s:Sound = new Sound(new URLRequest('URL here"));
    var sc:SoundChannel;
    My problem:
          I want to read the ID3 tag somehow and display the artist name or anything in the ID3 tag, onto the screen.
    Complication:
         I Have the URL change through user input, and naturally I want to update all the information with the new ID3 tags information.
    var s:Sound = new Sound(new URLRequest('NEW URL here"));
    Thank you for any help!

    I know I took it out because it didn't work. I had something like this:
    var soundLoaderContext:SoundLoaderContext = new SoundLoaderContext();
    soundLoaderContext.checkPolicyFile = true;
    var music:Sound = new Sound(new URLRequest("URL #1 (from my server)"));
    var sc:SoundChannel;//sound channel
    var isPlaying:Boolean = false;//checks f music is playing or not
    var pausePoint:Number = 0.00;//this variable is for the pause function
    music.addEventListener(Event.ID3, id3Handler);
    stop_btn.addEventListener(MouseEvent.CLICK, stopMusic);//stop function call
    function stopMusic(e:Event):void//stop function
         if(sc != null)//if music is playing
              sc.stop();//stops the music from playing
              isPlaying = false;//sets it to false(off)
              playPause_mc.gotoAndStop(1);//modifies graphic item on stage
         pausePoint = 0.00;//resets pause value
    play_btn.addEventListener(MouseEvent.CLICK, playMusic);//pause / play function call
    function playMusic(e:Event):void//pause / play function
         if (isPlaying) {// if it is playing
              pausePoint = sc.position;pausePoint get curreny value (position of song)
              sc.stop();//stops the music from playing
              isPlaying = false;//sets it to false(off)
              playPause_mc.gotoAndStop(1);//modifies graphic item on stage
         } else if (!isPlaying){// if it is not playing
              sc = music.play(pausePoint);//starts the music from the pausePoint value.
              isPlaying = true;//sets it to true(on)
              playPause_mc.gotoAndStop(2);//modifies graphic item on stage
    music2_btn.addEventListener(MouseEvent.CLICK, music2);//function call (if music is clicked)
    function music2(e:Event):void{//this function stops current playing music and resets graphics, assigns a new URL and starts playing it.
         if(isPlaying || pausePoint != 0)
              sc.stop();
              playPause_mc.gotoAndStop(1);
         music = new Sound(new URLRequest("URL #2 (from my server)"));
         music.addEventListener(Event.ID3, id3Handler);
         sc = music.play();
         isPlaying = true;
         playPause_mc.gotoAndStop(2);
    music1_btn.addEventListener(MouseEvent.CLICK, music1);
    function music1(e:Event):void{//this function stops current playing music and resets graphics, assigns a new URL and starts playing it. just like above only a different song.
         if(isPlaying || pausePoint != 0)
              sc.stop();
              playPause_mc.gotoAndStop(1);
         music = new Sound(new URLRequest("URL #1 (from my server)"));
         music.addEventListener(Event.ID3, id3Handler);
         sc = music.play();
         isPlaying = true;
         playPause_mc.gotoAndStop(2);
    function id3Handler(evt:Event):void {
          var id3:ID3Info = evt.target.id3;
          trace(id3.artist + ' - ' + id3.songName);
          name_txt = id3.songName;
          album_txt = id3.album;
          artist_txt = id3.artist;
    This is mostly just taking the exact code from the website I mentioned earlier.
    When I run this it outputs the trace command 1 time and nothing more. Only the trace(trace(id3.artist + ' - ' + id3.songName);) gets triggered once.
    No errors. No warning. Not working.
    Thank you for helping me!

  • How do I test if an object exists? in Flash CS4(AS3.0)

    I am trying to test if an object with an instance name of "test_mc" exists.
    How would i write the code with an if statement, i have no idear?
    ~Thank you for help tips and advice.

    Hello,
    using SPSiteDataquey, you are able to query multiple lists. if your column is only on those list, you just need to query the items and see if you get 2 elements on return.
    more info there :http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx
    Best regards, Christopher.
    Blog |
    Mail
    Please remember to click "Mark As Answer" if a post solves your problem or
    "Vote As Helpful" if it was useful.
    Why mark as answer?

  • Right Click Arrange  at runtime in code? in Flash CS4 (AS3)

    Hi,
    I was wondering if and how I can arrange movie clips in AS3 code. I want it to have the same effect as "Right Click > Arrange > Bring To Front" in the project, only during runtime and through code.
    Thank you for help and advice!

    What you can do if you want right click is create a new ContextMenu  and ContextMenuItem. You'll have to add a mouse click listener to each  of your stage items though so you can track the last one clicked;
    import flash.events.ContextMenuEvent;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    var  lastItem:MovieClip;
    var i:int;
    for(i =  0; i < stage.numChildren; ++i){
          stage.getChildAt(i).addEventListener(MouseEvent.MOUSE_DOWN,  itemClicked);
    function  itemClicked(e:MouseEvent):void
         lastItem =  e.currentTarget as MovieClip;
    var  rightClickMenu:ContextMenu = new ContextMenu();
    rightClickMenu.hideBuiltInItems();
    rightClickMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,  rightClickMenuClicked);
    var bringToFront:ContextMenuItem =  new ContextMenuItem("Bring To Front");
    rightClickMenu.customItems = [bringToFront];
    stage.showDefaultContextMenu  = false;
    stage.contextMenu = rightClickMenu;
    function  rightClickMenuClicked(e:ContextMenuEvent):void
          switch (e.mouseTarget.label)
              case "Bring To  Front":
                   if(lastItem != null){
                         lastItem.parent.addChild(lastItem);           
               break;
    NOTE: You do not need to  first remove the child to add it again. By adding an existing child  you're simply resetting it to the top depth.

  • Problem removing Objects from the stage in Flash CS4 (AS3.0)

    I have a problem with this code:
    this.addEventListener(Event.ENTER_FRAME, vanish);
    function vanish(event:Event):void{
         if(character_mc.hitTestObject(vanish_mc)){
              vanish_mc.parent.removeChild(vanish_mc);
    There are two overlapping objects on my stage: character_mc and vanish_mc.
    As soon as i start the scene[Ctrl+Enter] vanish_mc is VISUALLY removed. But the code still sees a collision somehow. How can i Entirely remove the object vanish_mc?
    Thank you for help and advice.

    Ah I think the problem is what my problem not which I proposed, my bad I was trying to keep it simple.
    the remove code in my problem actually looks like this:
    if(character_mc.hitTestObject(this["dollar_mc_"+String(i)])){
         removeChild(this["dollar_mc_"+String(i)]);
    I wanted it to be that way so I could add infinite "dollar_mc_" ' s without writing myself to death with code and or getting confused.
    Imagine it like a game where a character it picking up dollars, which would disappear once they intersect.
    And that exactly is what gives me that argument.
    Do you know a way i could write this code, or do you suggest to leave it that way...because it does run and work im just getting this argument while debugging.
    Thank you for all the help~

  • Global Variables in Flash CS4 (AS3) ?

    Hi,
    I  have another problem with my new project and I am looking to get answers for these two question:
    1.) Is there a way to define a global variable which can be accessed inside and movie clip or button? (where do you define it? is it changeable? can you pass it in by reference?)
    2.) If i have my main stage with some actionscript and a movie clip which has also some action script, IN WHICH ORDER does it execute?
    Thank you in advance for any help and tips!

    Thank you this is what i needed I got it to work now!
    But I do still have one last question on this topic.
    This is the Code:
    //this is in a file Actionscript File called glo.as
    package{
         public class glo{
              public static var widthOfSlider:Number = 5;
    // This code is in scene 1 > my_mc
    import glo;
    trace(glo.widthOfSlider);
    //This code is in scene 1 > my_mc > myNext_mc
    import glo;
    var numOfCovers = 6;
    var temp = glo.widthOfSlider;
    trace(glo.widthOfSlider);
    this.addEventListener(Event.ENTER_FRAME, centerB);
    function centerB(event:Event):void{
         for(var i = 0; i < numOfCovers ; i++ ){
              this["cover_btn_"+String(i)].y = 0;
              this["cover_btn_"+String(i)].x = temp;
              temp += this["cover_btn_"+String(i)].width + 5;
         glo.widthOfSlider = temp;
         trace(glo.widthOfSlider);
         this.removeEventListener(Event.ENTER_FRAME, centerB);
    When I run this I get the following output:
    5
    5
    5
    725.45
    725.45
    The first "5" is from the trace(glo.widthOfSlider); in scene 1 > my_mc
    The next two "5"'s are from the trace(glo.widthOfSlider); in scene 1 > my_mc > myNext_mc
    Is there a way so that I can first execute the code in scene 1 > my_mc > myNext_mc before the code in scene 1 > my_mc ?
    I am trying to get 725.45 through the trace(glo.widthOfSlider); in scene 1 > my_mc

  • Animation on One Frame? in Flash CS4(AS3)

    I have wondered if I can have an animation play on just the first Frame using ActionScript 3.0??
    Can I call a certain frame inside an animated movie clip, with ActionScript3.0?
    ~ Thanks for help and advice or tips.~

    Sure just use the instance name of the movieClip that you want to address. Something like this:
    button1.addEventListener(MouseEvent.MOUSE_UP,button1Up);
    function button1Up(event:MouseEvent):void {
       movieClipName.gotoAndPlay(3);
       // or something else...
    substitute the actual clip name for "movieClipName" in the function above.

  • SWF management - Adobe Flash CS4 AS3

    I want to design my own website in flash. But I have a couple of questions about swf management.
    I have a frame which has buttons -it will be my main page- each button will call a swf file as
    submenu.
    For example I have the "about us" button. On click a swf -about us- submenu will appear.
    1. When I call -on the click of a button- a swf file I want that file to have no background, cause I
    want as background my current frame. -generally I want each swf file that i call to have no
    background. How can I do that?
    2. I want to call an intro animation. Its a swf file -short presentation of my copmany it lasts 10
    sec- I want that animation to play before my menu appears. how can I do that? Is it good Idea to
    call that intro as an external swf file or should I make it in my current project -my main page-
    3. (its similar to 2) Lets say that I have 2 layers. In my first layer and frame(1) I will place the
    movieclip1. In my second layer and frame(2) I will place movieclip2. Each movie clip lasts 10
    seconds. When I test my project I want to my first movieclip to be played (10 seconds) and then my
    second clip (another 10 seconds). What  should my actionsript be? One way that I figured out its
    that in order for my first clip to be played for ten seconds I have to place it on
    24fps*10seconds=240frames -the first frame will be the keyframe.
    thank you all in advance

    One last thing. I want now to combine importing code with your code.
    With the following code I am loading intro.swf from file "clips" into my project - first frame (1) - in a current position (x,y). It is supposed (for the imported swf) to start when I test the movie (project) and to go to the next frame when the intro clip (the same imported swf) is done.
    var Xpos:Number=110;
    var Ypos:Number=180;
    var swf:MovieClip=new Loader();
    var defaultSWF:URLRequest=new URLRequest("clips/intro.swf");
    stop();
    loader.load(defaultSWF);
    loader.x=Xpos;
    loader.y=Ypos;
    addChild(loader);
    myclip1.addEventListener(Event.ENTER_FRAME,checkF);
    function checkF(e:Event):void{
         if(e.target.currentFrame==e.target.totalFrames){
         myclip1.removeEventListener(Event.ENTER_FRAME,checkF);
         removeChild(loader);
         nextFrame();
    my questions for the code are:
    1. should be there a stop(); before the loader? (in the upbove code there is)
    2.Is the removeChild(loader) placed in the right line?
    3.Any corrections?

  • General Question About common Instance Names in Flash CS4 (AS3)

    I tried something interesting recently. I had code effecting an object with the instance name : object_mc.
    Now I added another object and gave it the same instance name.
    The result was, that the code only effected the most recent added object (no error).
    Is there a way in flash to have multiple objects with the same instance name all being affected by one piece of code?
    ~ Thanks for any thoughts, advice or facts. ~

    Advice: avoid it... if you want to control different instances, give them different instance names.
    It depends on what you mean by "one piece of code".  Directly using the instance name to target the movieclips will work as you have seen already... Last one added gets the attention.
    To use the instance name to take action is doable more along the lines of testing each movie to see if it has the name, but still, you would have to target each using a different means. 
    For the piece of code below I have some number of objects on the stage and I test to see if they have an instance name assigned (object_mc) that is shared by some of them, and I am able to move them if they do, but I cannot use the instance name to target each of them for action... in this case I use the getChildAt method.
    for(var i=0; i<this.numChildren; i++){
    if(this.getChildAt(i).name == "object_mc"){
      this.getChildAt(i).x += 200;
      object_mc.x += 25;  // only moves the last object added

  • What happens with sound? in Flash CS4 AS3

    Hi,
    I have a couple of questions on the same topic:
    I was wondering what exactly is happening when I have this code:
    var sound:Sound = new Sound(new URLRequest("URL.mp3");
    does the mp3 file get downloaded?
         -If yes
              -where does it get downloaded to? Heap? Cache? or what do you call it
              -is there a way to stop or control the loading?
              -and can it be accesed(deleted) manually? is there a destructor?
                   -if possible
                        -How would you delete the memory?
                   -if not
                        -is there a way to do it with different code?
         -if not
             - at what point does it get downloaded? assuming the code continues like this:
               var soundChannel:SoundChannel;
               soundChannel = sound.play();
    I know there are many question, but they all depend on each other and i couldn't think of a easier way to ask.
    Thank you for any answers and tips!

    var sound:Sound = new Sound(new URLRequest("URL.mp3");
    does the mp3 file get downloaded? yes
         -If yes
              -where does it get downloaded to? Cache
              -is there a way to stop or control the loading? no
              -and can it be accesed(deleted) manually? ,yes.  is there a destructor? for the file, no
                   -if possible
                        -How would you delete the memory? same way you do for all flash objects:  ready sound for gc
                   -if not
                        -is there a way to do it with different code?

  • Forms in flash cs4 as3

    I Need to create a form that a user can fill out and have flash create a file and send the info  to a folder on the server. This is a hosted server so I am not able to do much in the way of scripts that i am aware of. What is the best way to do this?

    The PHP file is a server-side script so it goes on the server.
    These forums are not a resource for tutorials/lessons.  You will often get a response that tells you to search Google--it generally means that someone else has already prepared the information you're looking for, and usually in tutorial-level detail.  Don't underestimate Google and the Flash help documents.  ANY time I am stuck I turn to either of those two things to get my answers... not any forums, though sometimes the Google results that solve my problems are in forums.

Maybe you are looking for

  • Problem with Report and distribution file

    Hi. I have a report that create the paycheck for my customer's employe. My first group on the report is the email adresse of the employe, so i can cut the report end send it by mail to the said employe. 95% of the time it's working perfectly. But whe

  • How can I prevent Mail from applying actions (moving/copying/flagging/marking read) to duplicate messages?

    I use Mail to check multiple accounts. When I receive the same e-mail in multiple accounts, actions applied to an e-mail in one account often (though not always) affect duplicate messages in other accounts. Example 1 Someone sends an e-mail to both m

  • Java server pages and java script

    sir i want to know that is it possible to call the functions define in the jsp tag <% %> in the java Script tag? how can i call jsp function in html

  • Trying to Replace my f12 key...anyone know how?

    Hi, i just got a used iBook g4 and i love it! i got an f12 key to replace the one that was missing on the keyboard, but i dont know how to get it to stick on there. i thought i would be as easy as replacing a key on a PC keyboard, but i was mistaken.

  • New row in JTable

    Hey! I have a pretty stupid question... How can I add a new row in a JTable? Thanks, Edgar