actionscript 3 - Flash, using buttons (with mouse) to move -



actionscript 3 - Flash, using buttons (with mouse) to move -

so allow me clear here, not trying drag something, can find on keeping activated whilst clicked. know how move while clicked, have made version utilize mouse making in app, need utilize other mouse functions?

code:

mright.alpha = 0; mleft.alpha = 0; stage.addeventlistener(event.enter_frame, move); function move(e:event) { if(player.y >= 33 && player.y <= 763) { mright.addeventlistener(mouseevent.mouse_down, mrgh); function mrgh(e:mouseevent) { player.y -= 1; } mleft.addeventlistener(mouseevent.mouse_down, mlft); function mlft(e:mouseevent) { player.y += 1; } } else if(player.y < 33) { player.y = 33; } else if(player.y >= 763) { player.y = 763; } }

try :

as3 code :

var timer:timer = new timer(10) timer.addeventlistener(timerevent.timer, timer_on_timer) function timer_on_timer(e:timerevent){ move_player() } timer.start() var btn_left_pressed = false var btn_right_pressed = false btn_left.addeventlistener(mouseevent.mouse_down, btn_left_on_press) btn_left.addeventlistener(mouseevent.mouse_up, btn_left_on_release) function btn_left_on_press(e:mouseevent){ btn_left_pressed = true btn_right_pressed = false } function btn_left_on_release(e:mouseevent){ btn_left_pressed = false } btn_right.addeventlistener(mouseevent.mouse_down, btn_right_on_press) btn_right.addeventlistener(mouseevent.mouse_up, btn_right_on_release) function btn_right_on_press(e:mouseevent){ btn_right_pressed = true btn_left_pressed = false } function btn_right_on_release(e:mouseevent){ btn_right_pressed = false } function move_player(){ if(player.y >= 33 && player.y <= 763){ if(btn_right_pressed){ player.y -= 1 } else if(btn_left_pressed){ player.y += 1 } } else if(player.y < 33) { player.y = 33 } else if(player.y >= 763) { player.y = 763 } }

this of course of study easy code works, can add together many things start , stop timer, ...

actionscript-3 flash

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -