Note that there are some explanatory texts on larger screens.

plurals
  1. POAS3: drag by mouse or move by key
    text
    copied!<p>I've got 6 objects with drag'n'drop and hitTest function. It's obvious that when i drag one object to their hitTest area it's correct. </p> <p>But my question is that i want to control these 6 object by mouse and keyboard keys. if i dont want to drag them, then i can move them by key arrows. </p> <p>Second question is that when these two methods will be done if i want to move an object by key then i grab first free object which is not "hitTested"</p> <p>Can I do these things in AS3? Pretty weird solutions in these project but i need to know if is possible. </p> <p>Here's my code for drag and drop functions</p> <pre><code>package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.events.KeyboardEvent; import flash.display.MovieClip; public class Main extends MovieClip { var xPos:int; var yPos:int; var errors:int; var wins:int; public function Main():void { addListeners(objectone,objecttwo,objectthree,objectfour,objectfive); errors = 1; wins = 1; } private function getPosition(target:Object):void { xPos = target.x; yPos = target.y; } private function dragObject(e:MouseEvent):void { info.text = ""; getPosition(e.target); e.target.startDrag(true); } private function stopDragObject(e:MouseEvent):void { if (e.target.hitTestObject(getChildByName(e.target.name + "Target"))) { e.target.x = getChildByName(e.target.name + "Target").x; e.target.y = getChildByName(e.target.name + "Target").y; info.text = "Bingo!"; wins++; } else { e.target.x = xPos; e.target.y = yPos; bledy.text = "Wrong: " + errors++; } if(errors == 4) { errors = 1; gotoAndPlay(2); } if(wins == 9) { wins = 1; gotoAndStop(3); } e.target.stopDrag(); } private function addListeners(... objects):void { for (var i:int = 0; i &lt; objects.length; i++) { objects[i].addEventListener(MouseEvent.MOUSE_DOWN, dragObject); objects[i].addEventListener(MouseEvent.MOUSE_UP, stopDragObject); } } } } </code></pre> <p>Please give me some code tips! Cheers!</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