-
Thick as a Brick
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
-
Does this make a difference ?
var closeIt:BaseButton = new BaseButton();
-
Thick as a Brick
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
-
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.
-
Thick as a Brick
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
-
KoolMoves Moderator
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;
}
-
KoolMoves Moderator
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.
-
Thick as a Brick
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
-
KoolMoves Moderator
Well I'm honored
I thought "closeIt.on = false;" would be the variable.
Apparently note.
BTY check your PM for message from me
-
KoolMoves Moderator
In the code I see
_pl.visible
and there appears to be an event
_pl.addEventListener('visibility', updatePlaylistBtn);
-
Thick as a Brick
For all the help I get from you guys, I'm honored to make them.
Originally Posted by blanius
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
-
Thick as a Brick
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
-
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;
}
-
Thick as a Brick
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
-
That's because is should be trace instead of Trace .
-
Thick as a Brick
Changing to "trace" throws up no errors, but the button does nothing, not even change states.
Bob Godwin
-
Thick as a Brick
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
-
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.
-
Thick as a Brick
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
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|