0
votes

When I come to the text field type the button appear and if I get the text from the text that the button is disappeared. Now I want that when I click on the button to move the button is disappeared again and go to the next page.(movieClip).

I do everything in a frame and use addChild and removeChild to maneuver between the different pages. The butting stay the same all the time. (only make it visible/invisible)

so I do the same again. Is this possible and how can I do it best?

For now it remains visible on the second page.

2

2 Answers

0
votes

The button object is not scoped to be accessible within the handler function. You have to either see if it can be accessed via the event object that is passed to the handler function or create a custom event class that will contain the button object that can then be accessed in the handler function when you dispatch the change event for the textfield.

0
votes

If you don't want dig into creating custom classes you could use this code First place define some functions

import fl.controls.Button;
var pairs={}; 
var funcs={};
function ButtonConstructor(btnName:String,initX:Number,initY:Number,
                           connectedTF:TextField,clickFunction:Function){
    this[btnName] = new Button();
    this[btnName].x=initX;
    this[btnName].name=btnName;
    this[btnName].y=initY;
    this[btnName].visible =false;
    this[btnName].addEventListener('click',typicalClick);
    addChild(this[btnName]);
    pairs[connectedTF.name]=this[btnName];
    funcs[btnName]=clickFunction;
    connectedTF.addEventListener(Event.CHANGE,tfChange);
}
function tfChange(e:Event){
    pairs[e.target.name].enabled = true;
    pairs[e.target.name].visible = true;
    e.target.removeEventListener(Event.CHANGE,tfChange);
}
function typicalClick(e:MouseEvent){
    e.target.enabled = false;
    e.target.visible = false;
    funcs[e.target.name]();
}

Then you use them

function customFunction(){
    gotoAndStop(2);
}
ButtonConstructor('newBtn',100,100,firstTF,customFunction);