Hey All.
I’m trying to convert an mp3 player I built in AS2 into AS3.
So far it’s coming along somewhat nicely. I got it to read and trace the XML attributes etc. But, for the life of me I can’t get it to play…
I keep getting this error msg:
TypeError: Error #1034: Type Coercion failed: cannot convert true to flash.media.SoundLoaderContext.
at Mp3Player_cs3_fla::MainTimeline/playSong()
at Mp3Player_cs3_fla::MainTimeline/parseMp3()
at Mp3Player_cs3_fla::MainTimeline/LoadXML()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
This is my code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.media.*;
import flash.xml.*;
// Sound object
var s:Sound = new Sound;
var sc:SoundChannel = new SoundChannel;
var sContext:SoundLoaderContext = new SoundLoaderContext;
// Array of songs
var sa:Array = new Array();
// Currently playing song
var cps:Number = -1;
// load XML
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("songs.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
parseMp3(xmlData);
}
var nodes:Object = new Object();
function parseMp3(mp3:XML):void {
nodes = mp3.song.attributes();
for(var i:int = 0; i < nodes.length(); i++)
{
sa.push(new Song(nodes*.attributes.url, nodes*.attributes.artist, nodes*.attributes.title, nodes*.attributes.album));
}
playSong();
}
// playSong function
function playSong():void {
sContext.bufferTime = 1000;
if (cps == sa.length - 1) {
cps = 0;
s.load(sa[cps].earl, true);
} else {
s.load(sa[++cps].earl, true);
}
title_text.text = sa[cps].title;
album_text.text = sa[cps].album;
}
And I can’t seem to find where it’s going wrong.
The SoundLoaderContext-problem was also there before adding it to the code…
Is this a player security issue, perhaps?
Or am I missing something??
Any help is appreciated.
Thanks!
Stig