Skip to main content
Participating Frequently
February 21, 2011
Answered

Error #1006: value is not a function.

  • February 21, 2011
  • 2 replies
  • 1155 views

var buttons:Array = new Array;

var i:Number = 0;

for(var b:Number = 0; b < 5; b++)

{

var btn:Button = new Button;

btn.y = 15;

btn.x = b * 100 + 15;

btn.name = "btn" + (b + 1);

btn.label = String(b + 1);

buttons.push(btn.name);

addChild(btn);

}

var title_tf:TextFormat = new TextFormat();

title_tf.bold = "Bold";

title_tf.font = "Arial";

title_tf.size = 25;

title_tf.color = 0x000000;

title_tf.align = TextFormatAlign.CENTER;

next_btn.addEventListener(MouseEvent.CLICK, nextCLICK);

function nextCLICK(event:MouseEvent):void{

buttons.setStyle("textFormat",title_tf);

i++;

}

I have tried to solve this problems for days but i seems to keep getting this error. Anyone mind to help?

This topic has been closed for replies.
Correct answer kglad

use:

xHolyzx wrote:

var buttons:Array = new Array;

var i:Number = 0;

for(var b:Number = 0; b < 5; b++)

{

var btn:Button = new Button;

btn.y = 15;

btn.x = b * 100 + 15;

btn.name = "btn" + (b + 1);

btn.label = String(b + 1);

buttons.push(btn);

addChild(btn);

}

var title_tf:TextFormat = new TextFormat();

title_tf.bold = "Bold";

title_tf.font = "Arial";

title_tf.size = 25;

title_tf.color = 0x000000;

title_tf.align = TextFormatAlign.CENTER;

next_btn.addEventListener(MouseEvent.CLICK, nextCLICK);

function nextCLICK(event:MouseEvent):void{

buttons.setStyle("textFormat",title_tf);

i++;

}


2 replies

Inspiring
February 21, 2011

You are pushing the button.name into the buttons array. So when you retrieve the name it is just a string and there is no setStyle for strings.

Either you should push the instances themselves into the array:

buttons.push(btn)

Or you will need getChildByName to access the buttons.

Button(getChildByName(buttons)).setStyle("textFormat",title_tf);

In that case there is no reason for the compiler to think that the child retrieved by that line would be a Button, so you need to cast it as a Button. Or you could use a vector instead of an array to ensure that it was type safe.

Personally I'd go with a vector and putting the instances directly into the array instead of the names.

xHolyzxAuthor
Participating Frequently
February 21, 2011

Thanks Rothrock for explaining the details to me.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 21, 2011

use:

xHolyzx wrote:

var buttons:Array = new Array;

var i:Number = 0;

for(var b:Number = 0; b < 5; b++)

{

var btn:Button = new Button;

btn.y = 15;

btn.x = b * 100 + 15;

btn.name = "btn" + (b + 1);

btn.label = String(b + 1);

buttons.push(btn);

addChild(btn);

}

var title_tf:TextFormat = new TextFormat();

title_tf.bold = "Bold";

title_tf.font = "Arial";

title_tf.size = 25;

title_tf.color = 0x000000;

title_tf.align = TextFormatAlign.CENTER;

next_btn.addEventListener(MouseEvent.CLICK, nextCLICK);

function nextCLICK(event:MouseEvent):void{

buttons.setStyle("textFormat",title_tf);

i++;

}


xHolyzxAuthor
Participating Frequently
February 21, 2011

Thanks for helping kglad.

kglad
Community Expert
Community Expert
February 21, 2011

you're welcome.