FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


little ActionScript 3.0 app





kevinalle
Hi.
I made a small flash application I would like you to comment on..
http://tekage.com.ar/uploaded/spring.swf .
(You'll need Flash player 9 or above).

Here´s the code:
(Use it and distribute it as you like)

Code:
package{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.Event;
import flash.events.MouseEvent;

public class spring extends Sprite{
      var sp:Sprite=new Sprite();
      var ini:Array=new Array();
      var angle:Number=0;
      var a:Number=100;
      var go:Boolean=false;
      var goto:Array=new Array();
      var speed:Array=new Array();
      var center:Array=new Array();
      var acc:Array=new Array();
      var pos:Array=new Array();
      var oldmouse:Array=new Array();
      var mspeed:Array=new Array();
      
      public function spring():void{
         stage.scaleMode = "noScale";
         stage.align = "CC";
         init();
      }
      private function init():void{
         addChild(sp);
         center=[stage.stageWidth/2,stage.stageHeight/2];
         speed=[0,0];
         ini=center;
         pos=center;
         goto=center;
         acc=[0,0];
         sp.x=center[0];sp.y=center[1];
         addEventListener(Event.ENTER_FRAME,onEnterFrame);
         stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDwn);
         stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUpp);
         stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMov);
      }
      private function onEnterFrame(event:Event):void{
         angle=0;
         sp.graphics.clear();
         sp.graphics.lineStyle(2);
         if(go){
            goto=[mouseX,mouseY];
         }else{
            acc=[-((center[0]-goto[0])/4),-((center[1]-goto[1])/4)];
            speed=[speed[0]*.8+acc[0],speed[1]*.8+acc[1]];
            ini=[ini[0]-speed[0],ini[1]-speed[1]];
            goto=[ini[0],ini[1]];
            }
         for(var i=0;i<a;i++){
            angle+=.3;
            pos=[Math.sin(angle)*(a-i)-(center[0]-goto[0])/a/a*i*i,Math.cos(angle)*(a-i)-(center[1]-goto[1])/a/a*i*i];
            sp.graphics.lineStyle(2,0,1-(a-i)/a);
            if(i==0){sp.graphics.moveTo(pos[0],pos[1]);}else{sp.graphics.lineTo(pos[0],pos[1]);};
         }

      }
      private function onMouseDwn(event:MouseEvent):void{
         ini=[mouseX,mouseY];
         go=true;
      }
      private function onMouseUpp(event:MouseEvent):void{
         go=false;
         speed=[(ini[0]-center[0])/10-mspeed[0]*10,(ini[1]-center[1])/10-mspeed[1]*10];
         ini=[mouseX,mouseY];
         //trace(speed);
      }
      private function onMouseMov(event:MouseEvent):void{
         mspeed=[mouseX-oldmouse[0],mouseY-oldmouse[1]];
         oldmouse=[mouseX,mouseY];
      }
   }
}
brokenadvice
Pretty neat! It would be cool if you could move the spring, or there were instructions.
jabapyth
Nice job! it would be nice to have more options, or more springs Wink
tekage
wow, really neat...
it moves smoothly.
Do you re-draw the spring in evry frame or how did you animate it?
good job.
I'd like to see more of this!
kevinalle
As you can see., in the onEnterFrame event (on each frame), there is a spring generator
Code:
for(var i=0;i<a;i++){
angle+=.3;
pos=[Math.sin(angle)*(a-i)-(center[0]-goto[0])/a/a*i*i,Math.cos(angle)*(a-i)-(center[1]-goto[1])/a/a*i*i];
sp.graphics.lineStyle(2,0,1-(a-i)/a);
if(i==0){sp.graphics.moveTo(pos[0],pos[1]);}else{sp.graphics.lineTo(pos[0],pos[1]);};
}

It loops through an angle, and it depends on the spring center, and goto values (goto depends of mouse, speed acceleration). And it generates a spiral making many segments...

Good you liked it
Related topics
Install Mambo 4.5.2 And Vbulletin 3.0.7
The Best EJB 3.0 Flash PPT
3D modeling / imaging website question.
phpBB 3.0 / phpBB 2.2 / Olympus Discussion
Aquastrike's Realm Redux-3.0 BETA
phpBB 3.0 Beta1 Release
.NET 3.0 RC1 - What it is ????
Firefox 3.0 cada vez más cerca
.NET Framework 3.0
Safari 3.0 on Windows (beta)
Linus Torvalds: "No creo que necesitemos un kernel 3.0&
Opera 9.5 & Firefox 3.0 Not working. IE 7 Working. !?Pro
USB 3.0 SuperSpeed
Joomla! 3.0 support
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.