-
1. Re: Making a button stay in its down state on press/ release.
kglad May 21, 2010 9:14 AM (in response to xcmuddman)you have to use a movieclip.
-
2. Re: Making a button stay in its down state on press/ release.
xcmuddman May 21, 2010 10:04 AM (in response to kglad)so would i have to use a "load movie clip function" or "attach movie clip"? or can i just tell it to go to "ON" / "OFF" frames on its timeline?
-
3. Re: Making a button stay in its down state on press/ release.
Ned Murphy May 21, 2010 11:09 AM (in response to xcmuddman)It should be a self contained movieclip, just like a button is self-contained with different frames--you implement actionscript to control which frame it is on for various interactions/conditions.
-
4. Re: Making a button stay in its down state on press/ release.
kglad May 21, 2010 11:29 AM (in response to xcmuddman)create a new movieclip.
in its first frame attach a stop() and label that frame "up". put the up graphic on-stage.
in another frame, label "over" and place the over graphic on-stage.
likewise, for the "down" frame, if you want one.
then when you drag your movieclip from the library to the stage, in the properties panel, assign an instance name (eg, mc1).
then on that timeline attached to a frame use:
mc1.onRollOver=function(){
this.gotoAndStop("over");
}
mc1.onRollOut=function(){
this.gotoAndStop("up");
}
// and if you have a down frame:
mc1.onPress=function(){
this.gotoAndStop("down");
}
// and code your onRelease just like you did for your button
-
5. Re: Making a button stay in its down state on press/ release.
martin2562 May 23, 2010 10:05 AM (in response to xcmuddman)// I made a check box like this
// made a movie called checkbox, gave that movie 2 frames, in frame 1 gave it some actionscript
stop();
// and made a button for my unchecked state in frame 1and gave it some actionscript
on (release) {
gotoAndPlay(2);
}
// and in frame 2 of the movie I made a second button for my checked state and gave that some actionscript
on (release) {
gotoAndPlay(1);
}
// and last I gave frame 2 some script also
stop();
// Not sure if its the same sort of thing you want for a switch
-
6. Re: Making a button stay in its down state on press/ release.
kglad May 23, 2010 10:32 AM (in response to martin2562)1 person found this helpfulyou shouldn't attach code to objects.
-
7. Re: Making a button stay in its down state on press/ release.
martin2562 May 23, 2010 11:44 AM (in response to kglad)1 person found this helpfulchkbox_mc.onPress = function(){if(box==1){
box=0;this.gotoAndStop(1);
}else{
box=1
this.gotoAndStop(2);}
}would something like that work?
-
8. Re: Making a button stay in its down state on press/ release.
kglad May 23, 2010 12:18 PM (in response to martin2562)yes.
but a bit shorter, requiring no variable initialization and easier to read/debug is:
chkbox_mc.onPress=function(){
if(!this.toggle){
this.gotoAndStop(2);
} else {
this.gotoAndStop(1);
}
this.toggle=!this.toggle;
}
-
9. Re: Making a button stay in its down state on press/ release.
martin2562 May 24, 2010 5:31 AM (in response to kglad)thx again m8
-
10. Re: Making a button stay in its down state on press/ release.
kglad May 24, 2010 7:12 AM (in response to martin2562)you're welcome.
-
11. Re: Making a button stay in its down state on press/ release.
xcmuddman May 24, 2010 7:56 AM (in response to kglad)Nice!
Thank you KGLAD... I have 5 separate switches functioning nicely now.
I also coded a separate switch to controll all of them at once.
thanks!
Pat
-
12. Re: Making a button stay in its down state on press/ release.
kglad May 24, 2010 9:55 AM (in response to xcmuddman)you're welcome.
-
13. Re: Making a button stay in its down state on press/ release.
xcmuddman May 24, 2010 10:25 AM (in response to kglad)KGLAD - is there an easy way to have a movie clip with one instance switch to another movieclip with another instance in the same spot when you click on the initial movieclip?
-
14. Re: Making a button stay in its down state on press/ release.
martin2562 May 24, 2010 10:59 AM (in response to xcmuddman)you're welcome
-
15. Re: Making a button stay in its down state on press/ release.
kglad May 24, 2010 11:00 AM (in response to xcmuddman)what do you mean by, "..switch.."?
do you want them to switch positions on-stage? if yes, you can use:
function switchPosF(dobj1:DisplayObject,dob2:DisplayObject):void{
var tempx=dobj1.x;
var tempy=dobj1.y;
dobj1.x=dobj2.x;
dobj1.y=dobj2.y;
dobj2.x=tempx;
dobj2.y=tempy;
}
-
16. Re: Making a button stay in its down state on press/ release.
xcmuddman May 24, 2010 11:20 AM (in response to kglad)i have a movie clip "mc_Play" and after its pressed i want "mc_Pause" to take its place.
i tried this:
mc_MyVideo.playButton = mc_Play;
mc_MyVideo.pauseButton = mc_Pause;
mc_Play.onPress = function(){
this.attachMovie("mc_Pause", "Pause",
this.getNextHighestDepth());
mc_Play.removeMovieClip();
}
when i click "mc_Play" it starts playing "mc_MyVideo" and even switches to the mc_Pause clip, but "mc_Pause" has no effect or functionality on "mc_MyVideo"
-
17. Re: Making a button stay in its down state on press/ release.
kglad May 24, 2010 11:24 AM (in response to xcmuddman)what do you mean by, "...take its place..."?
-
18. Re: Making a button stay in its down state on press/ release.
xcmuddman May 24, 2010 11:37 AM (in response to kglad)By "take its place" i mean if its possible, for "mc_Play" to switch to "mc_Pause" in the same exact location on the stage...
for the actual movie clips and instance names to switch with each other
-
19. Re: Making a button stay in its down state on press/ release.
kglad May 24, 2010 12:03 PM (in response to xcmuddman)then use:
function switchPosF(dobj1:DisplayObject,dob2:DisplayObject):void{
var tempx=dobj1.x;
var tempy=dobj1.y;
dobj1.x=dobj2.x;
dobj1.y=dobj2.y;
dobj2.x=tempx;
dobj2.y=tempy;
}
-
20. Re: Making a button stay in its down state on press/ release.
xcmuddman May 24, 2010 12:50 PM (in response to kglad)thanks, KGLAD...
to make this work do i assign the function to an action such as onPress , etc???
i am also getting an error that says "the class or interface 'DisplayObject' could not be loaded...
-
21. Re: Making a button stay in its down state on press/ release.
kglad May 24, 2010 1:03 PM (in response to xcmuddman)sorry, that's as3 code.
use:
yourbutton.onRelease=function(){
switchPosF(this,anotherobject);
}
function switchPosF(obj1,obj2):void{
var tempx=obj1._x;
var tempy=obj1._y;
obj1.x=dobj2._x;
obj1.y=dobj2._y;
obj2.x=tempx;
obj2.y=tempy;
}
-
22. Re: Making a button stay in its down state on press/ release.
xcmuddman May 24, 2010 2:25 PM (in response to kglad)KGLAD - sorry i couldnt get that to work when i applied it to my own objects / instances...
there must be an easier way...
I am playing an FLV on my main stage and was trying to use the generic operators defined in flash for the play / pause buttons:
mc_MyVideo.playButton = mc_Play;
mc_MyVideo.playButton = mc_Pause;
Then i tried to modify this code to swap the buttons between each other on stage:
mc_Play.onPress = function(){
mc_Pause._x = 339.55;
mc_Pause._y = 12.2;
this._x = -100;
this._y = -100;
}
mc_Pause.onPress = function(){
mc_Play._x = 339.55;
mc_Play._y = 12.2;
this._x = -100;
this._y = -100;
}
the buttons work fine controlling mc_MyVideo when both are shown in different locations on the stage and without any other code.... but the moment i try to assign another function to either of them they stop controlling mc_MyVideo.
the closest i came was with an attachMovie function... when i pressed mc_Play it would start the movie and attach "mc_Pause" at the same time... thats the farthest i got...
- Pat
-
23. Re: Making a button stay in its down state on press/ release.
kglad May 24, 2010 3:01 PM (in response to xcmuddman)that's not going to work.
create pausePlay_mc with keyframes containing the obvious graphics and labeled:
pauseup, pauseover, pausedown, playup, playover, playdown.
you can then use:
pausePlay_mc.onRollOver=function(){
if(!this.toggle){
this.gotoAndStop("pauseover");
} else {
this.gotoAndStop("playover");
}
}
pausePlay_mc.onRollOut=function(){
if(!this.toggle){
this.gotoAndStop("pauseup");
} else {
this.gotoAndStop("playup");
}
}
pausePlay_mc.onPress=function(){
if(!this.toggle){
this.gotoAndStop("playdown");
mc_MyVideo.stop();
} else {
this.gotoAndStop("pausedown");
mc_MyVideo.play();
}
this.toggle=!this.toggle;
}
-
24. Re: Making a button stay in its down state on press/ release.
xcmuddman May 25, 2010 2:40 PM (in response to kglad)wow. nice bit of coding, KGLAD.
Thank you very very much!
- Pat
-
25. Re: Making a button stay in its down state on press/ release.
kglad May 25, 2010 3:45 PM (in response to xcmuddman)you're welcome.