actionscript 3 - timer method wont add textfield to sprite -


When I press the button below the keyboard, the text field is added to the phantom, but not through timer event calls. Why is it like this? Package {import flash.display.Sprite; Import Flash.events.KeyboardEvent; Import Flash. Text. Textfield; Import Flash. Import flash.events.TimerEvent; Expands Public Class Test Sprite (public function test) {var timer: timer = new timer (3); Stage.addEventListener (KeyboardEvent.KEY_DOWN, On Kidadown); Timer AddEventListener (TimerAventTMER, OnTime); Timer.start (); } Function on Kidadown (Event: Keyboard Event): Zero {// graphics.line style (10, Math.Randem) * 10000, 10); // graphics.drawCircle (100, 100, 80); Var txtFld: textfield = new textfield (); TxtFld.x = 200; TxtFld.y = 200; TxtFld.width = 25; TxtFld.height = 15; TxtFld.text = "90"; AddChild (txtFld); } Festival onTime (Event: Timer): Zero {var txtFld: TextField = New TextField (); TxtFld.x = 100; TxtFld.y = 100; TxtFld.width = 25; TxtFld.height = 15; TxtFld.text = "80"; AddChild (txtFld); }}}}

In timer event handler, you removed the incoming event object As is the timer , not timerEvent . Due to this the flash player has to face the error.

In addition, this code will continue to add textfields because the timer is looping and calling this function on each loop.

  function onTime (Event: Timer Event): Zero {// stop timer evt.target.stop (); Var txtFld: textfield = new textfield (); TxtFld.x = 100; TxtFld.y = 100; TxtFld.width = 25; TxtFld.height = 15; TxtFld.text = "80"; AddChild (txtFld); }    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -