hi, everyone, i am new and i need help
i hope my problem is not one everyone knows and talks about, but i couldn't really find an answear to it via google, and am a little bit desperate to find a solution..
problem is: the
addEventListener(Event.COMPLETE, onLoaded) does not finish what it should do before i call the
addEventListener(Event.ENTER_FRAME, loop) function, or so it seems..
WHY!?!?
i do not really understand why this is happening, maybe someone can explain to me where my thinking is wrong..
the error msg is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
that shouldn't be possible tho, since i initialize the concerning variable (sc:Soundchannel) beforehand..
code:
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class testprojekt extends Sprite
{
public var loader:URLLoader = new URLLoader();
public var sound: Sound = new Sound();
public var sc:SoundChannel = null;
public var xml:XML;
public var il: XMLList = new XMLList();
public var soundIndex:Number = 0;
public var soundEndIndex:Number;
public var speed:Number = 100;
public var chordList:XMLList;
public var testString:String;
public function testprojekt()
{
loader.load(new URLRequest("sound.xml"));
loader.addEventListener(Event.COMPLETE, onLoaded);
// chordList from SoundInput class
var sInput: SoundInput = new SoundInput("soundFile_test.xml");
chordList = sInput.getSoundInput();
addEventListener(Event.ENTER_FRAME, loop);
}
public function onLoaded(e:Event):void
{
// xml loaded
xml = new XML(loader.data);
il = xml.tracks.sound;
soundEndIndex = il.name.length();
// start first sound
sound = new Sound(new URLRequest("sounds/" + il.name[soundIndex]) );
sc = sound.play();
}
public function loop(e:Event):void
{
//trace("here is the error and i do not know why");
if (sc.position >= speed)
{
sc.stop();
setSound();
}
}
public function setSound():void
{
soundIndex++;
if (soundIndex < soundEndIndex)
{
trace(soundIndex);
sound = new Sound(new URLRequest("sounds/" + il.name[soundIndex]) );
trace(il.name[soundIndex]);
sc = sound.play();
}
else
{
removeEventListener(Event.ENTER_FRAME, loop);
}
}
}
}
thx for anyone reading this through