PDA

View Full Version : Dynamic Text Reference Error


RM3.0
08-27-2009, 12:45 AM
var btnInstance:Array = new Array();

for(var i = 0; i < 3; i++)
{
var test_mc:testMC = new testMC;
addChild(test_mc);
test_mc.x = 275;
btnInstance[i] = test_mc;
btnInstance[i].buttonMode = enabled;
btnInstance[i].text01.selectable = false;
}

//Labels
btnInstance[0].text01.text = "First Button";
btnInstance[1].text01.text = "Second Button";
btnInstance[2].text01.text = "Third Button";

//Positions
btnInstance[0].y = 64;
btnInstance[1].y = 128;
btnInstance[2].y = 192;

//Actions
btnInstance[0].addEventListener(MouseEvent.MOUSE_OVER, btnInAnim);
btnInstance[1].addEventListener(MouseEvent.MOUSE_OVER, btnInAnim);
btnInstance[2].addEventListener(MouseEvent.MOUSE_OVER, btnInAnim);

function btnInAnim(event:MouseEvent):void
{
var AnimTarget = event.target;

AnimTarget.gotoAndPlay(2);
AnimTarget.removeEventListener(MouseEvent.MOUSE_OV ER, btnInAnim);
AnimTarget.addEventListener(MouseEvent.MOUSE_OUT, btnOutAnim);
}

function btnOutAnim(event:MouseEvent):void
{
var AnimTarget = event.target;

AnimTarget.gotoAndPlay(9);
AnimTarget.removeEventListener(MouseEvent.MOUSE_OU T, btnOutAnim);
AnimTarget.addEventListener(MouseEvent.MOUSE_OVER, btnInAnim);
}

I have this code on my Flash File to make instances of three movie clips as buttons. The animation works for the buttons, but rolling over the text field gives the following error:

ReferenceError: Error #1069: Property gotoAndPlay not found on flash.text.TextField and there is no default value.
at LoopArrayExercise_fla::MainTimeline/btnInAnim()

I know why there's an error (it says it plain as day), but the only way I can think to fix it would be to break apart the text....of course, breaking apart the text would make the text uneditable. So, I wanted to see if anyone had any ideas on what could be done to rectify this.

A secondary problem I wanted to fix, is how the text field seems to block the button animation. (If I roll over or out of any section of the button that's not covered by the text field, the animation plays. Anywhere inside the text field is unresponsive.) I have a feeling fixing the primary problem would fix the secondary problem though...

Potemkyn
08-27-2009, 03:01 PM
Just maybe... You could consider adding a graphic in with an alpha of 0 that has the same width and height of the text. I've had movieclip/buttons not work properly because the only thing there WAS the text for the mouse to be over.

Mike

EvLSnoopY
08-27-2009, 03:30 PM
To fix the 2nd problem try:


yourTextField.mouseEnabled = false; /* With this set as false,
the mouse wont register the textfield */

I had this issue just a few days ago and I was SO relieved, to say the least, when I figured out about mouseEnabled and mouseChildren.

RM3.0
08-27-2009, 04:13 PM
Whoa....disabling mouseEnable fixed both problems. o.O I wasn't expecting it to fix the main problem, but the error doesn't come up anymore.

Nonetheless, thanks to both of you for your help. It's much appreciated. :)

EvLSnoopY
08-27-2009, 04:19 PM
No problem man. I'm just glad it worked out for you.