Thursday, 26 February 2015

TOGGLE BUTTON INVISIBLE FUNCTION AS2 AS3

TOGGLE BUTTON INVISIBLE FUNCTION AS3
---------------------------------------------------------------------------------------------------------------
TOGGLE BUTTON AS2 CODE
1) MAKE mc1 MOVIE CLIP = INSTANCE NAME mc1
2) INSIDE mc1 MAKE mc2 MOVIE CLIP  =  mc2
---------------------------------------------------------------------------------------------------------------




---------------------------------------------------------------------------------------------------------------

_root.mc1.mc2._visible = false;
mc1.onRelease=function(){
if(_root.mc1.mc2._visible == false) {
 _root.mc1.mc2._visible = true;

else {
_root.mc1.mc2._visible = false;
}
}


---------------------------------------------------------------------------------------------------------------
INVISIBLE BY BUTTON LABELS
COPY AND PASTE BELOW CODE
DOWNLOAD SOURCE FILES:
http://bit.ly/1LMUg3G
http://bit.ly/1E0hq5n
http://stackoverflow.com/questions/28125169/as2-on-off-button-that-adjusts-visibility
---------------------------------------------------------------------------------------------------------------
TOGGLE BUTTON AS2





-------------------------------------------------------------------------------------------------------------------------
GET BUTTON FROM COMPONENTS PANEL
GIVE INSTANCE NAME = btn1
EMPHASIZED BOX = NOT CHECKED
ENABLED BOX = CHECKED
CHANGE LABEL BOX  = START
LABEL PLACEMENT = RIGHT
SELECTED BOX = NOT CHECKED
TOGGLE BOX = CHECKED
VISIBLE BOX = CHECKED
--------------------------------------------------------------------------------------------------------------------
btn1.onPress = function(){
if(btn1.selected == true){
btn1.label = "START"
}
else {
btn1.label = "STOP"
}
}

-------------------------------------------------------------------------------------------------------------------------
TOGGLE BUTTON AS3
TOGGLE BUTTON INVISIBLE FUNCTION  AS2 AS3

----------------------------------------------------------------------------------------------------------------

GET BUTTON FROM COMPONENTS PANEL
GIVE INSTANCE NAME = btn1
EMPHASIZED BOX = NOT CHECKED
ENABLED BOX = CHECKED
CHANGE LABEL BOX  = START
LABEL PLACEMENT = RIGHT
SELECTED BOX = NOT CHECKED
TOGGLE BOX = CHECKED
VISIBLE BOX = CHECKED
-----------------------------------------------------------------------------------------------------------------

btn1.addEventListener(Event.CHANGE, changeHandler);
function changeHandler (event:Event):void{
if (event.currentTarget.selected == true){
btn1.label = "START";
}
else {
btn1.label = "STOP";
}
}

-------------------------------------------------------------------------------------------------------------------

//TAKE TWO BUTTONS COMPONENTS GIVE INSTANCE NAME "bn1""bn2"
//MAKE TEXT BOX GIVE INSTANCE NAME "txt1"
//bn1,bn2 Toggle Box Should Be Checked Without it Doesn't Work
bn1.addEventListener(MouseEvent.CLICK, fn1);
function fn1(evt:MouseEvent):void {
if (bn1.selected == true) {
bn1.label = "START"
}
else {
bn1.label = "STOP"
}}
bn2.addEventListener(MouseEvent.CLICK, fn2);
function fn2(evt:MouseEvent):void {
if (bn2.selected == true) {
bn2.label = "START"
}
else {
bn2.label = "STOP"
}}
addEventListener(Event.ENTER_FRAME, fn1fn2);
function fn1fn2(e:Event):void{
txt1.text =  String(bn1.label+ bn2.label)
if (bn1.label == "STOP" && bn2.label == "STOP" ) {
bn1.visible=false;
bn2.visible=false;
}}

---------------------------------------------------------------------------------------------------------------
UPPERCODE INVISIBLE BY TEXTBOX
COPY AND PASTE BELOW CODE
---------------------------------------------------------------------------------------------------------------

//TAKE TWO BUTTONS COMPONENTS GIVE INSTANCE NAME "bn1""bn2"
//MAKE TEXT BOX GIVE INSTANCE NAME "txt1"
//bn1,bn2 Toggle Box Should Be Checked Without it Doesn't Work
bn1.addEventListener(MouseEvent.CLICK, fn1);
function fn1(evt:MouseEvent):void {
if (bn1.selected == true) {
bn1.label = "START"
}
else {
bn1.label = "STOP"
}}
bn2.addEventListener(MouseEvent.CLICK, fn2);
function fn2(evt:MouseEvent):void {
if (bn2.selected == true) {
bn2.label = "START"
}
else {
bn2.label = "STOP"
}}
addEventListener(Event.ENTER_FRAME, fn1fn2);
function fn1fn2(e:Event):void{
txt1.text =  String(bn1.label+ bn2.label)
if (txt1.text == "STOPSTOP") {
bn1.visible=false;
bn2.visible=false;
}}

----------------------------------------------------------------------------------------------------------------------
SIMPLE TOGGLE BUTTON IN AS2
http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2
----------------------------------------------------------------------------------------------------------------------
btnToggle.stop();
btnToggle.toggled = false;
btnToggle.onRelease = function():Void {
this.toggled = !this.toggled; // this flip-flips the Boolean
if(this.toggled){
this.gotoAndStop(3);
}
else {
this.gotoAndStop(1);
}
}
-----------------------------------------------------------------------------------------------------------------------
SIMPLE TOGGLE BUTTON IN AS2
I USE ABOVE CODE IN THIS WAY
----------------------------------------------------------------------------------------------------------------------



-----------------------------------------------------------------------------------------------------------------------
CODE:
-----------------------------------------------------------------------------------------------------------------------

btn1.onPress = function():Void {

btn1.btn1= !btn1.btn1; 

if (btn1.btn1){
btn1.gotoAndStop("STOP"); //MOVIE CLIP SECOND FRAME LABEL


else {
btn1.gotoAndStop("START");//MOVIE CLIP FIRST FRAME LABEL
}

}

-----------------------------------------------------------------------------------------------------------------------
SIMPLE TOGGLE BUTTON IN AS2
https://www.youtube.com/watch?v=BM_vCpEKYDI
----------------------------------------------------------------------------------------------------------------------

SIMPLE TOGGLE BUTTON IN AS2
TOGGLE BUTTON INVISIBLE FUNCTION  AS2 AS3


-----------------------------------------------------------------------------------------------------------------------
CODE:
-----------------------------------------------------------------------------------------------------------------------
//INSIDE BUTTON ACTION SCRIPT PANEL
on(press){
play();
}
------------------------------------------------------------------------------------------------------------------
NEED TWO STOPS FIRST FRAME AND SECOND FRAME
//INSIDE FRAME1
stop(); 
//INSIDE FRAME2
stop();
--------------------------------------------------------------------------------------------------------------------









EmoticonEmoticon