0

I'm working on a Flash MP3 Player using Actionscript 3. I have a dynamic textbox with an instance name of 'timerText' on the stage next to the buttons for play, pause etc.

The code for updating the timerText field with the current minutes and seconds is called from a function called onEnterFrame, which is attached to the EnterFrame event listener.

I have embedded the fonts in the Dynamic Textbox, and when I call the trace function to print out the current text from the Dynamic textbox, it prints out the time as it should. The textbox itself, however, doesn't change at all.

There is 1 frame in my timeline, with the following actions attached:

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.events.Event;

// Stop the Player
stop();

/**
* Declare some Variables
*/

// Get the MP3 File
var req:URLRequest = new URLRequest('audio/alice-track-1.mp3');

// Create a Sound Object
var snd:Sound = new Sound();

// Create a Sound Channel
var channel:SoundChannel;

// Initialise the Pause Position
var pausePosition:int = 0;

// Boolean for Is Playing(?)
var isPlaying:Boolean = false;

// Set the Play Buffer to 5 Seconds
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);

// Load the Requested URL into the Snd Var, along with the Context
snd.load(req, context);

// Create the Play Channel
channel = snd.play();

// Set IsPlaying to TRUE initially
isPlaying = true;

/**
* Play Music Function
*/
function playSound(event:MouseEvent):void {
    if (isPlaying == false) {
        channel = snd.play(pausePosition);
        isPlaying = true;
    }
}

/**
* Stop Music Function
*/
function stopSound(event:MouseEvent):void {
    channel.stop();
    pausePosition = 0;
    isPlaying = false;
}

/**
* Pause Music Function
*/
function pauseSound(event:MouseEvent):void {
    pausePosition = channel.position;
    channel.stop();
    isPlaying = false;
}

// Add the Button Event Listeners
playBtn.addEventListener(MouseEvent.CLICK, playSound);
stopBtn.addEventListener(MouseEvent.CLICK, stopSound);
pauseBtn.addEventListener(MouseEvent.CLICK, pauseSound);

// Add the OnEnterFrame Event Listener
addEventListener(Event.ENTER_FRAME, onEnterFrame);

/**
* Initialisation / OnEnterFrame Function
*/
function onEnterFrame(event:Event):void {
    var totalSeconds:Number = channel.position / 1000;
    var minutes:Number = Math.floor(totalSeconds / 60);
    var seconds = Math.floor(totalSeconds) % 60;

    if (seconds < 10) {
        seconds = '0' + seconds;
    }

    timerText.text = (minutes + ':' + seconds);
trace(timerText.text);
}
Andy Mills
  • 135
  • 2
  • 13
  • You don't need to have it run every frame since you're only displaying minutes and seconds, set up a timer at 900 msecs instead. Also, do you need a textbox or textfield for this. – Gone3d Feb 07 '13 at 15:59
  • I've got a dynamic textbox on the stage with an instance name of 'timerText'. – Andy Mills Feb 07 '13 at 16:09
  • definitely sounds like fonts not embedded properly. does it work without embedding fonts? –  Feb 07 '13 at 17:00
  • 1
    @Gone3d This is off-topic, but that's not very elegant since the time display will occasionally be showing the same time for almost 2 seconds and 900 ms the rest of the time. – david.emilsson Feb 07 '13 at 17:18
  • 900ms is .9 sec - it makes sure that you update in less than a sec with a little buffer. If you find there are issues at 900ms, lower it to .5 sec or 500ms. If you're at 30fps, that's 33ms, big difference. – Gone3d Feb 07 '13 at 17:49

2 Answers2

0

It might be a font-embedding issue.

Pleas make sure that you have enabled the all button in the font-embed options. Look athis image- https://i.stack.imgur.com/1Sskp.png

Also, make sure the font color is not same as the background color.

Joe Slater
  • 2,483
  • 6
  • 32
  • 49
  • I've double checked, and the font is definitely embedded (I've selected 'All' characters). The font is set to white, on a black background, so it should be visible. As I said, when I trace timerText.text, it prints the correct values. There just doesn't seem to be any output to the textbox. – Andy Mills Feb 08 '13 at 12:25
0

by looking at this, I'm seeing that "minutes" and "seconds" are numbers, not Strings.

I thought that would give you an error, but you could always try

timerText.text = String(minutes) + ":" + String(seconds);

That casts the numbers to a string and allows them to be displayed in the textfield.