I have a class named TextLink. The text is meant to be clicked on and it should dispatch an event (which I’m not too concerned about yet)… currently it just prints out a message.
The class takes an x, y, and a string to set the text. Dead simple…
But it crashes the browser.
Instance calls in main:
package {
import flash.display.Sprite;
import nav.text.TextLink;
public class test_array_of_objects extends Sprite
{
public function test_array_of_objects()
{
var ary:Array = new Array(5);
var i:uint;
var ty:uint;
var tx:uint = 30;
for(i=0; i<ary.length; i++)
{
ty = i * 20 + 20;
var tmp:TextLink = new TextLink(tx, ty, "some text" + i.toString());
ary.push(tmp);
}
}
}
}
Class:
package nav.text
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.external.ExternalInterface;
public class TextLink extends Sprite
{
public var tf:TextField = new TextField();
public function TextLink(tx:uint, ty:uint, tft:String)
{
tf.text = tft;
tf.x = tx;
tf.y = ty;
tf.autoSize = TextFieldAutoSize.LEFT;
addChild(tf);
}
private function rollfunc(e:Event):void
{
ExternalInterface.call("console.log", "got a clicky");
}
/*
protected function rollfunc(e:Event):void
{ //dispatch a custom event
dispatchEvent(new Event(Event.COMPLETE));
}
*/
}
}
You’ll notice that I have commented out the rollfunc function because I was going to add it later-
What I would like to do here is to dispatch an event for whoever is listening to the class so that I can do something specific with the event of clicking on the text. The instance would be defined by an addEventListener() call.
Thanks
This is an infinite loop.
ary.push()will increaseary.lengthon each iteration andiwill never be able to catch up to it.I think you want @outis’s second suggestion here; i.e.
ary[i] = tmpOr just create an empty array and push things into it.