Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2008
    Location
    England
    Posts
    31
    Thanks
    6
    Thanked 0 Times in 0 Posts

    mp3 player using as3 MVC

    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

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

    But in my new file external to my FLA i have created this
    PHP Code:
    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

    PHP Code:
    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

  • #2
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •