Add child to stage on keydown help


hi,

 

still newcomer actionscript:

 

i trying add movieclip named 'mycellclass' library stage when 'enter' pressed on keyboard.

 

can tell me wrong short code below:

 

[as]

import flash.ui.keyboard;

import flash.events.keyboardevent;

 

stage.addeventlistener(keyboardevent.key_down, keydownhandler);

function keydownhandler(event : keyboardevent) : void

{

    if (event.keycode == keyboard.enter)

    {

    var movieclip:mycellclass = new mycellclass();

    addchild(movieclip);

    movieclip.x = 205;

    movieclip.y = 120;

    movieclip.name = "mycellclass";

    }

}

[/as]

 

any appreciated.

your code works fine.

 

don't forget press ctrl + enter , on preview screen, go menu , select control then disable keyboard shortcuts.



More discussions in ActionScript 3


adobe

Comments