Hey all,
I am a total flash newbie, and I'm looking to build an audio player that uses flash in the back-end, javascript in the front-end. Therefore I do not need the "movie" capabilities of flash. I have the actionscript class that runs the audio, the javascript that tells the actionscript to play, and swfobject to embed the flash. I don't know how to run code once actionscript loads. I've been looking at flex and mxml for possible solutions.. but I'm not sure.. here's what I have.
Audio.as
package {
import flash.media.*;
import flash.net.*;
public class Audio {
public var file:String;
public var audio:Sound;
public var channel:SoundChannel;
public function Audio(f:String) {
file = f;
audio = new Sound();
audio.load(new URLRequest(file));
}
public function play(resumeTime:uint = 0):void {
if(channel)
channel.stop();
channel = audio.play(resumeTime * 1000);
}
public function pause():void {
channel.stop();
}
public function progress():Number {
if(!channel || audio.length == 0) return -1;
var p:Number = channel.position / 1000;
var l:Number = audio.length / 1000;
return p / l;
}
public function time():Object {
if(!channel || audio.length == 0) return {};
var p:Number = channel.position / 1000;
var min:int = p / 60;
var sec:int = p % 60;
return {"minutes" : min, "seconds" : sec};
}
}
}
Javascript:
// Prepare SWF Object
var flashvars = {};
flashvars.file = file;
var params = {};
params.allowscriptingaccess = "always";
params.allownetworking = "all";
var attributes = {};
attributes.id = "FlashAudio";
swfobject.embedSWF("Audio.swf", "audio", 1, 1, "9.0.0", false, flashvars,params,attributes);
swfobject.addLoadEvent(function() {
AudioCore.audio = swfobject.getObjectById('FlashAudio');
});
I know relatively how to use ExternalInterface, I just don't know how to run code once the swf loads. Where's the "main" function!?