0

I have a 3 dimensional object rotating in a Flash video file (embedded in a MovieClip). Its 100 frames long.

It's trivial to drag an object in Flash to affect its x/y coordinates with startDrag()...

But I want to be able to drag the object and change the currentFrame of the MovieClip depending upon the position of the mouse from left to right.

My best idea is :

  • Have an invisible box around the object
  • Initiate startDrag() on the invisible box
  • Set currentFrame during the drag operation based on the position from origin
  • Snap the invisible box back to the original position when the drag operation is complete - and record the frame offset for next time someone drags it

Just want to make sure there's no easier trick - or something 'out-of-the-box' (either AS3 code or IDE script) that I could use.


Edit I'm pursuing this approach and it's working quite well. However Flash doesn't seem to like seeking randomly backwards through a movie clip. If I drag to the right it plays smoothly, but if I drag to the left it is very jumpy trying to seek to a previous frame. Is there some AS3 to optimize 'reverse play'?

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • doesn't help with my question - but here's the best tutorial i've found on dragging : http://www.flashandmath.com/basic/dragdroptour/dd_tour1.html – Simon_Weaver Apr 08 '11 at 04:43

3 Answers3

1

Regarding playing your clip backwards, it may be a better option to have another 100 frames after the initial 'forward' movement that play the rotation animation backwards. Then you could use simple logic to change between the 1-100 (forward) frames and the 101-200 (backward frames).

This way you're not asking flash to play a clip backwards, which it's not designed to do.

Glitcher
  • 1,078
  • 6
  • 14
1

Well, if you want AS3 code:

stage.addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );

//triggered on MouseEvent.MOUSE_DOWN
private function beginDrag(e:MouseEvent):void
{
  stage.addEventListener(MouseEvent.MOUSE_MOVE, drag);
  stage.addEventListener(MouseEvent.MOUSE_UP, endDrag);
  stage.addEventListener(Event.DEACTIVATE, endDrag);
  stage.addEventListener(Event.MOUSE_LEAVE, endDrag);
  contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, endDrag);
}

private function drag(e:MouseEvent):void
{
  //do stuff
}

private function endDrag(e:Event):void
{
  stage.removeEventListener(MouseEvent.MOUSE_MOVE, drag);
  stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag);
  stage.removeEventListener(Event.DEACTIVATE, endDrag);
  stage.removeEventListener(Event.MOUSE_LEAVE, endDrag);
  contextMenu.removeEventListener(ContextMenuEvent.MENU_SELECT, endDrag);
}

Just be aware that there are some issus with dragging in flash.

Community
  • 1
  • 1
zzzzBov
  • 174,988
  • 54
  • 320
  • 367
1

This actually looks quite interesting! I would suggest looking at MOUSE_MOVE in the Adobe Livedocs. You may not need to actually drag an object.

What I would attempt, in this case, would be to calculate the difference between my start X (which should be the location where your mousedown event happened) and my current X (event.StageX for your MOUSE_MOVE, I believe) - basically, how far the user has moved the mouse in the X direction. I would then divide this value by a "step value". For instance, if I wanted to move one frame for every 20 units on the x-axis, my step value would be 20. You can then use Math.floor() or int() to truncate the value to translate to your frame animation. (The merits of this method - if you define the step value in a variable, you can change it at runtime, meaning that you can have fast and slow drag speeds, or whatever else you want to do.)

This basically lets you skip the "dragging an invisible object" step.

Good luck.

  • interesting suggestion on avoiding a draggable object. I definitely will need an object to represent the bounds of the video (because it's smaller than the video clip), and I think I'd like to take advantage of the 'conventional wisdom' surrounding draggable objects but its definitely an option. plus theres always some kind of primeval pleasure dragging an object in one line of code :-) – Simon_Weaver Apr 07 '11 at 23:51
  • @Simon Ah - the object doesn't fill the entire stage. One thing to note, from a UI perspective, is that if you drag to manipulate an object, the drag shouldn't stop until the user releases the mouse button. This means that if you start a drag within object bounds and drag outside of it, the object should still spin when the user's outside of the object bounds. You'll notice this behavior in most OSes; people are used to it, so I'd suggest implementing it if you can. Check [this thread.](http://stackoverflow.com/questions/1563434/detect-mouse-leave-stage-while-dragging-in-actionscript-3) –  Apr 08 '11 at 00:53
  • @Simon Note, however, that my solution would only work with this method within the Flash SWF - my solution is global, but the solution in that thread lets you drag outside of the SWF area, which may be useful depending on your application. (Many users "flick" the mouse for quick movement - if you anticipate this, I would suggest using the object drag method.) –  Apr 08 '11 at 00:55
  • ya - our designer wanted people to be able to 'throw' the object and for it to rotate and gracefully slow down. thats out of scope now. wish i had time to play with something like that, but it's not going to add to any more sales in my opinion! – Simon_Weaver Apr 08 '11 at 03:48
  • @Simon Hmm. Using the MOUSE_MOVE method, that actually would be doable - logically, you could check the delta of x/y, and set a velocity based on the initial size of it. (Baslcally, your mouse speed translates t oyour animation speed.) It makes sense from a programming perspective, but I haven't implemented it, so of course I'm trivializing the issue! :P –  Apr 11 '11 at 05:17