Re: [Flashcoders] AS3 continuous loop on mouse down

2007-05-13 Thread Michael Boski

if you want something to happen over and over do a set interval on
mouse down and clear interval on mouse up.


On 5/13/07, dave matthews <[EMAIL PROTECTED]> wrote:

hi All,

  What is the syntax for a continuous loop in AS3?

  Have working code for a code loop using mouse down - one frame-main
timeline, but can't figure out how to maintain the rate of movement when the
mouse is stationary with the mouse button still in down position.

thanks,
Dave_Matthews

  Place symbol instance named 'circle' on stage.
  Paste this code on actions frame:

import flash.events.MouseEvent;
this.stop();

var circleOrigX:Number;
var circleOrigY:Number;
var curOrigX:Number;
var curOrigY:Number;
var panRateX:Number;
var panRateY:Number;

function panSetUpDrag(event:MouseEvent):void {
circleOrigX = event.stageX - circle.x;
circleOrigY = event.stageY - circle.y;
curOrigX= event.stageX ;
curOrigY= event.stageY ;
stage.addEventListener(MouseEvent.MOUSE_MOVE, panloop);
}

function panloop(event:MouseEvent):void {
/*want this loop to operate while mouse is stationary
- causing pan actions to reposition circle
at rate based on distance of cursor from start*/

panRateX =  (event.stageX -curOrigX) * 3 ;
panRateY =  (event.stageY -curOrigY) * 3 ;
circle.x = event.stageX - circleOrigX - panRateX;
circle.y = event.stageY - circleOrigY - panRateY;
event.updateAfterEvent();
}
function PanStopDrag(event:MouseEvent):void {
gotoAndStop(1);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, panloop);

}

stage.addEventListener(MouseEvent.MOUSE_DOWN, panSetUpDrag);
stage.addEventListener(MouseEvent.MOUSE_UP, PanStopDrag);

_
More photos, more messages, more storage—get 2GB with Windows Live Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] AS3 continuous loop on mouse down

2007-05-13 Thread David Ngo
If this is for AS3, then I would say use the Timer class:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/Timer.
html


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Michael
Boski
Sent: Sunday, May 13, 2007 1:17 PM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] AS3 continuous loop on mouse down

if you want something to happen over and over do a set interval on
mouse down and clear interval on mouse up.


On 5/13/07, dave matthews <[EMAIL PROTECTED]> wrote:
> hi All,
>
>   What is the syntax for a continuous loop in AS3?
>
>   Have working code for a code loop using mouse down - one frame-main
> timeline, but can't figure out how to maintain the rate of movement when
the
> mouse is stationary with the mouse button still in down position.
>
> thanks,
> Dave_Matthews
>
>   Place symbol instance named 'circle' on stage.
>   Paste this code on actions frame:
>
> import flash.events.MouseEvent;
> this.stop();
>
> var circleOrigX:Number;
> var circleOrigY:Number;
> var curOrigX:Number;
> var curOrigY:Number;
> var panRateX:Number;
> var panRateY:Number;
>
> function panSetUpDrag(event:MouseEvent):void {
> circleOrigX = event.stageX - circle.x;
> circleOrigY = event.stageY - circle.y;
> curOrigX= event.stageX ;
> curOrigY= event.stageY ;
> stage.addEventListener(MouseEvent.MOUSE_MOVE, panloop);
> }
>
> function panloop(event:MouseEvent):void {
> /*want this loop to operate while mouse is stationary
> - causing pan actions to reposition circle
> at rate based on distance of cursor from start*/
>
> panRateX =  (event.stageX -curOrigX) * 3 ;
> panRateY =  (event.stageY -curOrigY) * 3 ;
> circle.x = event.stageX - circleOrigX - panRateX;
> circle.y = event.stageY - circleOrigY - panRateY;
> event.updateAfterEvent();
> }
> function PanStopDrag(event:MouseEvent):void {
> gotoAndStop(1);
> stage.removeEventListener(MouseEvent.MOUSE_MOVE, panloop);
>
> }
>
> stage.addEventListener(MouseEvent.MOUSE_DOWN, panSetUpDrag);
> stage.addEventListener(MouseEvent.MOUSE_UP, PanStopDrag);
>
> _
> More photos, more messages, more storage-get 2GB with Windows Live
Hotmail.
>
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migratio
n_HM_mini_2G_0507
>
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com