thanks flep!
got another problem though..
Code:
package com.externalFiles
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.events.ContextMenuEvent;
import flash.net.URLRequest;
public class gwPlayerv2 extends MovieClip
{
//modify for xml based mp3
private var xml:loadsXML;
public var object_array:Array;
public var link_array:Array;
//public var temp_url:String;
public var totalSong:int;
//sound baryabowls!!
private var _channel:SoundChannel;
private var _sound:Sound;
private var _playing:Boolean;
//initialize position of the sound (kung sang segundo na ung tugtog
private var _sposition:int=0;
private var _songNumber:int=0;
public function gwPlayerv2()
{
initVar();
initButtons();
kuhaXML();
}
//simulan ang variables for multiple songs
public function initVar():void
{
//url=new Array();
object_array=new Array();
link_array=new Array();
_playing=false;
}
private function kuhaXML():void
{
xml=new loadsXML(this);
trace('kuha XML link_array '+link_array);
trace('total song '+totalSong);
}
//*--FIX BUTTONS--**********************************************************************************************************//
//initialize buttons
public function initButtons():void
{
playSound.addEventListener(MouseEvent.MOUSE_OVER,chPlayImage);
pauseSound.addEventListener(MouseEvent.MOUSE_OVER,chPauseImage);
stopSound.addEventListener(MouseEvent.MOUSE_OVER,chStopImage);
forwardSound.addEventListener(MouseEvent.MOUSE_OVER,chForwardImage);
playSound.addEventListener(MouseEvent.MOUSE_UP,playSong);
pauseSound.addEventListener(MouseEvent.MOUSE_UP,pauseSong);
stopSound.addEventListener(MouseEvent.MOUSE_UP,stopSong);
forwardSound.addEventListener(MouseEvent.MOUSE_UP,forwardSong);
}
//change button's images
public function chPlayImage(event:Event):void
{
trace('Mouse Over PLAY');
trace('link_array '+link_array[0]);
}
public function chPauseImage(event:Event):void
{
trace('Mouse Over PAUSE');
}
public function chStopImage(event:Event):void
{
trace('Mouse Over STOP');
}
public function chForwardImage(event:Event):void
{
trace('Mouse Over FORWARD');
}
//play song function. pag napindot ung play button
public function playSong(event:MouseEvent):void
{
if(_playing)
{
//do nothing since it's already playing
trace('Music already playing');
//_channel.addEventListener(Event.SOUND_COMPLETE,songFinish);
}
else
{
//_channel.stop();
//para iplay kung san ka nagpause
//_channel=_sound.play(_sposition);
_playing=true;
//_songNumber=0;
initSound(_songNumber);
trace('Music not playing');
}
}
//pause song function
public function pauseSong(event:MouseEvent):void
{
if(_playing)
{
_sposition=_channel.position;
_channel.stop();
}
else
{
_channel=_sound.play(_sposition);
}
_playing=!_playing;
}
//stop song
public function stopSong(event:MouseEvent):void
{
_channel.stop();
_sposition=0;
_playing=false;
}
//forward song
public function forwardSong(event:MouseEvent):void
{
if (_songNumber
{
_channel.removeEventListener(Event.SOUND_COMPLETE,songFinish);
_songNumber=_songNumber+1;
_channel.stop();
_sposition=0;
trace ('IF forward sound position '+_channel.position);
trace ('forward songnumber '+_songNumber);
trace ('forward total song '+totalSong);
initSound(_songNumber);
_channel.addEventListener(Event.SOUND_COMPLETE,songFinish);
}
else
{
_channel.removeEventListener(Event.SOUND_COMPLETE,songFinish);
_songNumber=0;
_channel.stop();
_sposition=0;
trace ('forward sound position '+_sposition);
trace ('ELSE forward total song '+totalSong);
initSound(_songNumber);
_channel.addEventListener(Event.SOUND_COMPLETE,songFinish);
}
}
//*--PLAY SONG--***********************************************************************************************************//
//initialize song function
private function initSound(n:Number):void
{
_channel.removeEventListener(Event.SOUND_COMPLETE,songFinish);
_sound=new Sound(new URLRequest(link_array[n]));
trace ('sound position '+_sposition);
_channel=_sound.play(_sposition);
_playing=true;
_channel.addEventListener(Event.SOUND_COMPLETE,songFinish);
}
/*private function playSound():void
{
_channel=_sound.play();
}*/
private function songFinish(e:Event):void
{
if (_songNumber
{
_channel.removeEventListener(Event.SOUND_COMPLETE,songFinish);
_songNumber=_songNumber+1;
_channel.stop();
_sposition=0;
trace ('IF forward sound position '+_channel.position);
trace ('forward songnumber '+_songNumber);
trace ('forward total song '+totalSong);
initSound(_songNumber);
_channel.addEventListener(Event.SOUND_COMPLETE,songFinish);
}
else
{
_channel.removeEventListener(Event.SOUND_COMPLETE,songFinish);
_songNumber=0;
_channel.stop();
_sposition=0;
trace ('forward sound position '+_sposition);
trace ('ELSE forward total song '+totalSong);
initSound(_songNumber);
_channel.addEventListener(Event.SOUND_COMPLETE,songFinish);
}
}
}
}
now i get this error
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.externalFiles::gwPlayerv2/::initSound()
at com.externalFiles::gwPlayerv2/playSong()
now i know my logic is right that everytime you click the play song it will remove the listener first then sets up the variables and instances and then adds the listener again..now what i don't know why is that it keeps throwing the null method..
Bookmarks