Note that there are some explanatory texts on larger screens.

plurals
  1. POActionscript Arrays of Objects?
    text
    copied!<p>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.</p> <p>Instance calls in main:</p> <pre><code>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&lt;ary.length; i++) { ty = i * 20 + 20; var tmp:TextLink = new TextLink(tx, ty, "some text" + i.toString()); ary.push(tmp); } } } } </code></pre> <p>Class:</p> <pre><code>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)); } */ } } </code></pre> <p>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.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload