PDA

View Full Version : Dynamic text


lovemail1356
12-31-2008, 09:44 AM
Hi..
Does anyone know what code i can use to link a button to dynamic text?
For example what i want to happen is, when i click that button, certain text will show up in the dynamic text area. The code should be actionscript 3.0 though.

Thank you.

tBeck
12-31-2008, 09:56 AM
import flash.events.*;

// make sure it has an instance name , unless
// its created at run-time.
// our event listener which listens for mouse click events
yourbtn.addEventListener(MouseEvent.CLICK,clickBtn );

// our mouse click handler
function clickBtn(e:MouseEvent):void{
dyntext.text = "text here";
}

lovemail1356
12-31-2008, 10:01 AM
What if my button is called "oneB"
and my dynamic text is identified as answer1

would my code then be:

import flash.events.*;
oneB.addEventListener(MouseEvent.CLICK,oneB)
function oneB(e:MouseEvent):void{
answer1.text = "wrong answer";
}

?
Thank you so so much!

tBeck
12-31-2008, 10:14 AM
Yes, but do not give the function the same name as the button, because it's ambiguous and you will get duplication errors in flash.

lovemail1356
12-31-2008, 10:48 AM
I'm very sorry
but i'm getting an errror message that i don't quite get...

1061: Call to a possibly undefined method addEventListener through a reference with static type Function.

Can you tell me what they are telling me please? so that i can fix the problem

Thank you so much

tarafenton
12-31-2008, 04:00 PM
You are close, but you can't use oneB twice, once for the name of the button and another for the function. All that you have to do is rename your function.

import flash.events.*;
oneB.addEventListener(MouseEvent.CLICK,_click)
function _click(e:MouseEvent):void{
answer1.text = "wrong answer";
}