dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: if dynamic text = xxx, then text = yyy

  1. #1
    Junior Member
    Join Date
    Apr 2003
    Posts
    21

    if dynamic text = xxx, then text = yyy

    I have a few dynamic text boxes that get their info depending on both song position of a music player and im having a few problems.

    When I hit my "stop button", my song position, due to my coding, ends up saying "0:0"

    I was wondering if theres any way to automatically turn "0:0" into "0:00" and not have it mess up the songposition when it is told to be played again.

    Additionally, I have a song preloader that reads "NaN" before it is told what song to load. So, I would like to change "NaN" to "0" (zero).

    Any and all help greatly appreciated,
    thanks
    Tyler

  2. #2
    Senior Member
    Join Date
    Feb 2002
    Location
    Lebanon
    Posts
    573
    hello,
    what you can do is to change the number(s) appearing ion the dynamic text field to a string then append new chars to that string then put it in the text field again.

    Code:
    // suppose the value of the text field ("txt") is number 12
    // now you want it to appear "12:00", do this:
    txt.text = txt.text.toString()+":00";
    // now when you want to read that value and play the song
    // accordingly you have to get the NUMBER, and not the string
    var num = parseInt(txt.text);
    // check the reference to know what exact output can you get
    that's it. You can even change the "NaN" to something (a number or another string) in the say way.

  3. #3
    Junior Member
    Join Date
    Apr 2003
    Posts
    21
    well, i found out that the 0:0 was a flaw in my code somewhere

    the "NaN" thing im still not getting

    all of my actionscript is on a single frame and I dont know how to get "percentload" (% downloaded box var) to equal 0% but as soon as the player begins to download a song have it update accordingly....what you have here didnt seem to do anything at all

  4. #4
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Are you using sound objects?

  5. #5
    Junior Member
    Join Date
    Apr 2003
    Posts
    21
    the flash mp3 player calls out to a text file which loads mp3s into flash dynamically when a user requests them

    well...here, actually...

    http://www.undergroundsoundonline.co...toblaster.html

    you will most likely need to hit refresh until i get a preloader to properly preload everything

    the text area inside the grey area is the text box in question

    My code is as follows:

    this.onEnterFrame = function() {
    sload = mySound.getBytesLoaded();
    stotal = mySound.getBytesTotal();
    percentload = (Math.round((sload/stotal)*100))+"%";
    if (counter<2) {
    counter = counter+1;
    // txt file telling where the mp3s are and their names.
    loadVariablesNum("tracks.txt", 0);
    // character to split track
    songtitle = musictitle.split(":");
    count2 = 0;
    songplaying = songtitle[count2];
    }
    if (stopped != true) {
    mySoundDuration = Math.round(_root.mySound.duration/1000);
    mySoundPosition = Math.round(_root.mySound.position/1000);
    texttime = mySoundPosition;
    timemin = 0;
    if (texttime<10) {
    texttime = "0"+texttime;
    }
    while (texttime>=60) {
    texttime = texttime-60;
    timemin = timemin+1;
    if (texttime<10) {
    texttime = "0"+texttime;
    }
    }
    }
    timeformat = timemin+" :"+texttime;
    };
    stop();

    the bold is my code problem....its a divide by zero error, im positive
    Last edited by tylerromo; 05-26-2003 at 01:43 AM.

  6. #6
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749

    Divide and conquer

    Without seeing your FLA, your onEnterFrame function has a lot of tasks to do. It would be a good idea to split them up. For eg:

    PHP Code:
    function no_play_display() {
        
    timeformat "0 :00";
        
    songplaying "Paused";
        
    percentload "0%";
    }
    function 
    load_tracklist() {
        
    loadVariablesNum("tracks.txt"0);
        
    songtitle musictitle.split(":");
    }
    function 
    load_sound_tracker() {
        
    sload mySound.getBytesLoaded();
        
    stotal mySound.getBytesTotal();
        if (
    stotal) {
            
    // Only do this if a total size has been received.
            
    percentload = (Math.round((sload/stotal)*100))+"%";
        }
    }
    function 
    monitor_sound() {
        
    mySoundPosition Math.round(mySound.position/1000);
        
    // This gives the remainder from dividing by 60 (the number of seconds)
        
    timeseconds mySoundPosition%60;
        
    // Subtract the seconds and divide by 60 for the minutes
        
    timeminutes = (mySoundPosition-timeseconds)/60;
        
    timeseconds "00"+timeseconds;
        
    timeseconds timeseconds.substr(-2);
        
    timeformat timeminutes+" :"+timeseconds;
    }
    function 
    load_track(tracknum) {
        
    no_play_display();
        
    songplaying songtitle[tracknum];
        
    mySound.loadSound(songtitle[tracknum]);
        
    mySound.onLoad = function() {
            
    mySound.start;
            
    onEnterFrame monitor_sound;
        };
        
    onEnterFrame load_sound_tracker;
    }
    playbutton.onRelease = function() {
        
    load_track(0);
    };
    load_tracklist();
    no_play_display();
    stop(); 

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