A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Add Button to Mediaplayer

  1. #1
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217

    Add Button to Mediaplayer

    I'm trying to add a button to the media player. I tried this code in the setup.as but it killedthe player:
    Code:
    var closeIt:baseButton = new baseButton();
    closeIt.setSkin('stop_png');
    closeIt.move(30,23);
    closeIt.setSize(20,54);
    closeIt.addEventListener('click', __event4);
    addChild(closeIt);
    The image is in the image list and I tried importing km.components, but nothing works. I'm missing something, no doubt.
    Bob Godwin

  2. #2
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Does this make a difference ?

    var closeIt:BaseButton = new BaseButton();

  3. #3
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    Why yes it does. Not sure how I missed that. Now that it shows up, how do I get it to work! I'm trying to get it to hide the play list & display. Here's the code I'm using:
    Code:
    private function __event4(e:Event):void {
           if (playlist.visible = true) {
                  playlist.visible = false;
                  setDisplay(0,0,0,0,0x000000);
           } 
           else {
                  playlist.visible = true;
                  setDisplay(21,70,263,192,0x000000);
           }
    }
    It hides it, but stops doing anything after that.
    Bob Godwin

  4. #4
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    I don't know what's going wrong.
    If you aren't already using a debug version of the flash player, I suggest you do and see if it mentions anything. Using trace to see what's going on also can be very helpful.

  5. #5
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    It was that = should be == in the if statement. So it works, but not quite how I want. What I'm trying to do now is use the "on" event for the button (I have it set as a switch). I tried this code, but it doesn't work:
    Code:
    private function __event4(e:Event):void {
           if (closeIt.on == false) {
                  closeIt.on = true;
                  playlist.visible = false;
                  setDisplay(0,0,0,0,0x000000);
           } 
           else {
                  closeIt.on = false;
                  playlist.visible = true;
                  setDisplay(21,70,263,192,0x000000);
           }
    }
    Using closeIt.on does change the initial button state, but it doesn't work in the function. I also tried to set up a variable that would change with everything else but that didn't work either. I put the amp up with the playlist.visible code for the heck of it:
    fAmp
    The new button is just kinda sitting there right now (It looks like a stop button) but you'll get the gist of it.
    Last edited by bobgodwin; 11-25-2010 at 07:40 AM.
    Bob Godwin

  6. #6
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Whoa... Uh is it just me or when I push the square button twice I see my username on the face of the speaker?

    put a trace statement inside the else, I'll bet it's not firing...

    And I prefer not testing for false so I would probably write this.

    Code:
    private function __event4(e:Event):void {
           if (closeIt.on) {
                  Trace ("in IF");
                  playlist.visible = true;
                  setDisplay(21,70,263,192,0x000000);
           } 
           else {
                  Trace ("in Else");
                  playlist.visible = false;
                  setDisplay(0,0,0,0,0x000000);              
           }
    
               closeIt.on = !closeIt.on;
    }

  7. #7
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Funny I am now trying to get a fullscreen button on the brushed metal player.

    I really need to make a new custom skin but I haven't had the time to relearn the skinning for the AS3 Mediaplayer.

  8. #8
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    Yes, it's a rockin' Blanius Blaster. Got one for Wilbert, Chris & Stoke too.

    Setup.as button code:
    Code:
    var closeIt:BaseButton = new BaseButton(); 
    closeIt.setSkin('stop_png');
    closeIt.operationMode = 2;
    closeIt.move(30,23);
    closeIt.addEventListener('click', __event4);
    
    closeIt.on = false;
    addChild(closeIt);
    event.as:
    Code:
    private function __event4(e:Event):void {
           if (closeIt.on) {
                  Trace ("in IF");
                  playlist.visible = true;
                  setDisplay(21,70,263,192,0x000000);
           } 
           else {
                  Trace ("in Else");
                  playlist.visible = false;
                  setDisplay(0,0,0,0,0x000000);              
           }
    
               closeIt.on = !closeIt.on;
    }
    Here's the error code I get:
    Code:
    ReferenceError: Error #1065: Variable closeIt is not defined.
    	at km.instances::__MediaPlayer1/__event4()
    	at flash.events::EventDispatcher/dispatchEventFunction()
    	at flash.events::EventDispatcher/dispatchEvent()
    	at km.components::BaseButton/mouseUp()
    I thought "closeIt.on = false;" would be the variable.
    Bob Godwin

  9. #9
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Well I'm honored

    I thought "closeIt.on = false;" would be the variable.
    Apparently note.

    BTY check your PM for message from me

  10. #10
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    In the code I see
    _pl.visible

    and there appears to be an event
    _pl.addEventListener('visibility', updatePlaylistBtn);

  11. #11
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    For all the help I get from you guys, I'm honored to make them.

    Quote Originally Posted by blanius View Post
    In the code I see
    _pl.visible

    and there appears to be an event
    _pl.addEventListener('visibility', updatePlaylistBtn);
    Not sure what that is. Could that be the internal code for the playlist button?
    I do have this code to close the playlist on click:
    Code:
    setup.as
    addEventListener('playlistSet', __event3);
    playlist.addEventListener('change', __event3);
    playlist.addEventListener('noChange', __event3);
    
    events.as
    private function __event3(e:Event):void {
    	playlist.visible = e.type == 'playlistSet';
    
    }
    Bob Godwin

  12. #12
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    Shouldn't the var "closeIt" be declared in "var closeIt:BaseButton = new BaseButton();" code? You'd think the button wouldn't even show up if it weren't.
    Bob Godwin

  13. #13
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    It's a scope issue.
    The code in setup.as is executed inside a function.
    Declaring a variable there makes it not visible everywhere.
    Try moving the declaration.

    setup.as:
    Code:
    closeIt.setSkin('stop_png');
    closeIt.operationMode = 2;
    closeIt.move(30,23);
    closeIt.addEventListener('click', __event4);
    
    closeIt.on = false;
    addChild(closeIt);
    event.as:
    Code:
    var closeIt:BaseButton = new BaseButton(); 
    
    private function __event4(e:Event):void {
           if (closeIt.on) {
                  Trace ("in IF");
                  playlist.visible = true;
                  setDisplay(21,70,263,192,0x000000);
           } 
           else {
                  Trace ("in Else");
                  playlist.visible = false;
                  setDisplay(0,0,0,0,0x000000);              
           }
    
               closeIt.on = !closeIt.on;
    }

  14. #14
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    Doing that way throws up this error:
    Code:
    ReferenceError: Error #1065: Variable Trace is not defined.
    	at km.instances::__MediaPlayer1/__event4()
    	at flash.events::EventDispatcher/dispatchEventFunction()
    	at flash.events::EventDispatcher/dispatchEvent()
    	at km.components::BaseButton/mouseUp()
    Still does nothing. Argh!!!
    Bob Godwin

  15. #15
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    That's because is should be trace instead of Trace .

  16. #16
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    Changing to "trace" throws up no errors, but the button does nothing, not even change states.
    Bob Godwin

  17. #17
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    New tactic. Trying this:
    Code:
    private function __event4(e:Event):void {
           if (closeIt.on == false) {
                  trace ("in if");
                  closeIt.on = true;
                  playlist.visible = true;
                  setDisplay(21,70,263,192,0x000000);
           } 
           else  {
                  trace ("in else");
                  closeIt.on = false;
                  playlist.visible = false;
                  setDisplay(0,0,0,0,0x000000);              
           }
    }
    Gets the play list & display to go away, but it won't come back.

    Edit
    Found the solution!!!
    famp
    Code:
    var closeIt:BaseButton = new BaseButton();
    
    private function __event4(e:Event):void {
           if (closeIt.on == false) {
                  trace ("in if");
                  closeIt.on = false;
                  playlist.visible = true;
                  setDisplay(21,70,263,192,0x000000);
           } 
           else  {
                  trace ("in else");
                  closeIt.on = true;
                  playlist.visible = false;
                  setDisplay(0,0,0,0,0x000000);             
           }
                  //closeIt.on = !closeIt.on;
    }
    Doesn't seem right (Changing "closeIt.on = false;" to "closeIt.on = false;"???)

    I have an amp with your name on it Mr. Brants!!!
    Last edited by bobgodwin; 11-27-2010 at 03:36 AM. Reason: Found the answer!!!
    Bob Godwin

  18. #18
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    I'm glad you got it working
    You don't have to set the button state.
    If you set the button up as a switch, the component itself takes care of changing the button state when you click it.
    You should be able to remove those closeIt.on = ... lines.

  19. #19
    Thick as a Brick bobgodwin's Avatar
    Join Date
    Sep 2003
    Location
    Metro Detroit
    Posts
    217
    Got it working pretty much how I want it now. I even got the power light to work! The closeIt button is sitting mysteriously next to it 'cause I don't know what to call it. May be I'll just put a "?" under it. Anyway, I learned how to make a button and that makes you pawns I my feidish plan (Insert maniacal laughter here). Seriously, I learned a lot about AS3 doing this, and, as always, appreciate the help. I've got custom amps for Wilbert & Blanius. Should I PM them to you? Anyway, here's a link:
    fAmp Test
    Bob Godwin

  20. #20
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Nice work Bob !
    Yes, you can PM me

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center