Tuesday 15 June 2010

Flash actionscript 3 function requires mouse click event? -



Flash actionscript 3 function requires mouse click event? -

for flash actionscript 3 running in cs6 having issue in function run after mouse click event, don't know why i've tried can come with, , there doesn't appear similar issues online.

this basic template programme i'm creating in frame one. it's designed when click on 1 of possible buttons check if right button or not , take next frame

stop(); var buttons:array=new array(oport); //list of buttons var correct:string="oport"; //button name var gotoframe:int=2; var win:string=null; const next_frame:int=0; var removeotherlisteners:function=function():void{}; addlisteners(); function addlisteners():void { (var i:int=0; i<buttons.length; i++) { buttons[i].addeventlistener(mouseevent.click, checkbutton); } } function removelisteners():void { (var i:int=0; i<buttons.length; i++) { buttons[i].removeeventlistener(mouseevent.click, checkbutton); } } //checks button onclick , applies functions above function checkbutton(e:mouseevent):void { removelisteners(); removeotherlisteners(); removeotherlisteners=function():void{}; mouse.show(); if (e.currenttarget.name==win) { gotoandstop("win"); } else if (e.currenttarget.name==correct) { if (gotoframe<=0) { nextframe(); } else { gotoandstop(gotoframe); } } else { gotoandstop("lose"); } }

this on sec frame code designed cs4 should still work. frame presenting issue, when come in from frame one, must click on screen before can start typing. if type before clicking on screen nil happen.

var ldown:boolean = false; var sdown:boolean = false; var ddown:boolean = false; stage.addeventlistener(keyboardevent.key_down, onkeyboarddown); function onkeyboarddown(e:keyboardevent):void { if (e.keycode == keycodes.l) { ldown = true; } if (ldown == true) { if (e.keycode == keycodes.s) { sdown = true; } } if (sdown == true) { if (e.keycode == keycodes.d) { stage.removeeventlistener(keyboardevent.key_down, onkeyboarddown); gotoandstop(5); } } }

this class referred in keycodes

package { public class keycodes { public static const a:uint = 65; public static const b:uint = 66; public static const c:uint = 67; public static const d:uint = 68; public static const e:uint = 69; public static const f:uint = 70; public static const g:uint = 71; public static const h:uint = 72; public static const i:uint = 73; public static const j:uint = 74; public static const k:uint = 75; public static const l:uint = 76; public static const m:uint = 77; public static const n:uint = 78; public static const o:uint = 79; public static const p:uint = 80; public static const q:uint = 81; public static const r:uint = 82; public static const s:uint = 83; public static const t:uint = 84; public static const u:uint = 85; public static const v:uint = 86; public static const w:uint = 87; public static const x:uint = 88; public static const y:uint = 89; public static const z:uint = 90; public function keycodes() { // constructor code } } }

thank answers or advice.

most likely, focus issue caused browser. security precaution browser won't give flash focus without click. solution utilize javascript give swf focus on page load.

see adobe's solution > http://helpx.adobe.com/flash/kb/give-keyboard-focus-embedded-movie.html

and recommend seek putting of code document class. eliminate bugs occur separating code frame scripts. well, making code re-usable.

actionscript-3 flash actionscript flash-cs6 cs4

No comments:

Post a Comment