...

View Full Version : mp3 player using as3 MVC



dewy
03-10-2009, 10:19 PM
hi,

I am very new to actionscript and am trying to create a simple mp3 player that takes songs from an xml file. I have managed to do it the old fashioned way by having everthing in a single actionscript file within my fla, but i would like to be able to use inheritance to make the mp3 player work with my Model View Controller diagram that i have made.

Within my flash file i have made this



play_btn.addEventListener(MouseEvent.CLICK, playSong);
function playSong(event:Event):void
{
if(songPlaying == false)
{
trace("play music");
}
}


But in my new file external to my FLA i have created this


package
{
import flash.display.SimpleButton;

public class buttons extends SimpleButton
{
public function playSong():void
{
trace("play music");
}
}
}


and am calling it within my fla with


play_btn.playSong();

I am exporting my play_btn to work with the buttons.as file.

What i cannot figure out is where to put my Event listener and my boolean. If i put it in my fla i get an error and if i put it in my .as i get an error also.

I will appreciate any type of help thanks

clustaCoder
04-08-2009, 03:02 PM
Hi, I suppose its too late but this may be helpful to others anyway::

package
{
import flash.display.SimpleButton;
import flash.events.*;

public class buttons extends SimpleButton
{

private var songPlaying=false;

public function buttons(){
addEventListener(MouseEvent.MOUSE_DOWN, playSong);
}

public function playSong(e:MouseEvent):void
{
if(!songPlaying)
trace("play music");
}
}
}

If you add the constructor function with the addEventListener inside it, it will setup the event listener when you first add an instance of the button.
Put the songPlaying variable inside of the class definition.

Also, you will have to import the events (or just MouseEvent) and type the input event as MouseEvent for the handler function (playSong).

Hope that helps



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum