Skip navigation
Currently Being Moderated

Buttons & RemoveChild() problem

Sep 18, 2012 8:26 PM

Tags: #flash #as3 #newbie #game

Firstly,


how do I set the buttons to only be selected ONCE , if another button is clicked .. it will give no response.


Secondly,


what do i do to clear the image from the UrlRequest from the selected buttons (image will be displayed) with removeChild


As you can see below, all the buttons can be selected .. all at once. which is wrong.

and also, the removeChild will only work without error #2025 if two buttons (and two images) were shown. which is also wrong.



stop();


aa1.addEventListener(MouseEvent.CLICK, ona1Click);

bb1.addEventListener(MouseEvent.CLICK, onb1Click);

cc1.addEventListener(MouseEvent.CLICK, onc1Click);

next1.addEventListener(MouseEvent.CLICK, onNext1Click);

home1.addEventListener(MouseEvent.CLICK, onHome1Click);


var Q1a:Loader = new Loader();

var Q1b:Loader = new Loader();

var Q1c:Loader = new Loader();

var Q1next:Loader = new Loader();

var Q1home:Loader = new Loader();


//the name of the function has to match what you're calling from the event listener

function ona1Click(evt:MouseEvent):void {


var myQ1a:URLRequest=new URLRequest("wrong.png");

Q1a.load(myQ1a);

addChild(Q1a);


Q1a.x=320;

Q1a.y=180;

}


function onb1Click(evt:MouseEvent):void {



var myQ1b:URLRequest=new URLRequest("tick.png");

Q1b.load(myQ1b);

addChild(Q1b);


Q1b.x=320;

Q1b.y=260;

}


function onc1Click(evt:MouseEvent):void {


var myQ1c:URLRequest=new URLRequest("wrong.png");

Q1c.load(myQ1c);

addChild(Q1c);


Q1c.x=320;

Q1c.y=340;


}



function onNext1Click(evt:MouseEvent):void {


removeChild(Q1b);

removeChild(Q1a);


gotoAndPlay(2);


}


function onHome1Click(evt:MouseEvent):void {

gotoAndPlay(17);

}


HELP me.

 
Replies
  • kglad
    61,985 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 18, 2012 10:54 PM   in reply to naha_ks

    1. you can use the mouseEnabled property of your buttons to disable them all when one is clicked.

    2. use unloadAndStop() (if publishing for fp10+) or unload (if publishing for fp 9) applied to your loader.

     

    p.s.  just use one loader.  you have no need for the others if you're disabling the buttons that would use the other loaders.

     
    |
    Mark as:
  • kglad
    61,985 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 19, 2012 6:43 AM   in reply to naha_ks

    to disable all your buttons use:

     

    enableAllF(false);

     

    function enableAllF(b:Boolean):void{

    aa1.mouseEnabled=b;

    bb1.mouseEnabled=b;

    cc1.mouseEnabled=b;

    next1.mouseEnabled=b;

    home1.mouseEnabled=b;

    }

     
    |
    Mark as:
  • kglad
    61,985 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 19, 2012 1:22 PM   in reply to naha_ks

    i'm not sure what other two buttons you are mentioning.

     

    the code i gave will disable 5 buttons (aa1,bb1,cc1,next1,home1) you listed when any one of them is clicked.  is that what you want?

     
    |
    Mark as:
  • kglad
    61,985 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 19, 2012 9:19 PM   in reply to naha_ks

    none of those code for buttons. 

     

    the last two are event listener functions associated with two buttons (bb1 and cc1).  the first is part of an event listener function for aa1

     

    this is your button listener code where you define button behavior for 5 objects:

     

    aa1.addEventListener(MouseEvent.CLICK, ona1Click);

    bb1.addEventListener(MouseEvent.CLICK, onb1Click);

    cc1.addEventListener(MouseEvent.CLICK, onc1Click);

    next1.addEventListener(MouseEvent.CLICK, onNext1Click);

    home1.addEventListener(MouseEvent.CLICK, onHome1Click);

     

    if you want to disable all but the clicked button for aa1,bb1 and cc1 in your ona1Click, onb1Click and onc1Click functions add:

     

    disableF(evt);

     

    and add the following to your code:

     

    var buttonA:Array=[aa1,bb1,cc1];

    function disableF(e:Event):void{

    for(var i:int=0;i<buttonA.length;i++){

    if(buttonA[i]!=e.currentTarget){

    buttonA[i].mouseEnabled=false;

    }

    }

    }

     
    |
    Mark as:
  • kglad
    61,985 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 20, 2012 6:22 AM   in reply to naha_ks

    again:

     

    in your ona1Click, onb1Click and onc1Click functions add:

     

    disableF(evt);

     

    // evt references the parameter name you chose for the MouseEvent.CLICK event in those listener functions.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points