※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


FORKED
  1. // forked from beinteractive's 4. Tween grouping with BetweenAS3
  2. package
  3. {
  4.     import flash.display.Sprite;
  5.     import flash.text.TextField;
  6.     import flash.events.MouseEvent;
  7.     import org.libspark.betweenas3.BetweenAS3;
  8.     import org.libspark.betweenas3.tweens.ITween;
  9.     import org.libspark.betweenas3.events.TweenEvent;
  10.     import org.libspark.betweenas3.easing.*;
  11.     
  12.     public class Sample extends Sprite
  13.     {
  14.         public function Sample()
  15.         {
  16.             (addChild(_field = new TextField()) as TextField).text = 'Click to start';
  17.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  18.         }
  19.         private var _field:TextField;
  20.         
  21.         private function mouseUpHandler(e:MouseEvent):void
  22.         {
  23.             stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  24.             var box1:Box = addNewBox(50);
  25.             var box2:Box = addNewBox(150);
  26.             
  27.             // Serial (Start in specified order) Tween
  28.             var t:ITween = BetweenAS3.serial(
  29.                 BetweenAS3.tween(box1, {x: 220}, null1.2, Cubic.easeOut),
  30.                 BetweenAS3.tween(box2, {x: 220}, null1.2, Cubic.easeOut)
  31.             );
  32.             t.addEventListener(TweenEvent.COMPLETE, completeHandler);
  33.             t.play();
  34.         }
  35.         private function completeHandler(e:TweenEvent):void
  36.         {
  37.              _field.text = 'Complete!';
  38.          }
  39.         
  40.         private function addNewBox(y:Number):Box
  41.         {
  42.             var box:Box = new Box();
  43.             box.x = 20;
  44.             box.y = y;
  45.             addChild(box);
  46.             return box;
  47.         }
  48.     }
  49. }
  50. import flash.display.Sprite;
  51. internal class Box extends Sprite
  52. {
  53.     public function Box()
  54.     {
  55.         graphics.beginFill(0);
  56.         graphics.drawRect(-10, -102020);
  57.         graphics.endFill();
  58.     }
  59. }
noswf
  1. // Click to apply attraction force.
  2. // Please view all steps, to see how i got to this point.
  3. // I did not / do not, know when I'll stop these iterations but they are fun.
  4. // Sort of forked 5. Tween controlling BetweenAS3
  5. // forked from onedayitwillmake's Proximity step 6
  6. // forked from onedayitwillmake's Proximity step 5
  7. // forked from onedayitwillmake's Proximity step 4
  8. // forked from onedayitwillmake's forked from: Proximity step 3
  9. // forked from onedayitwillmake's forked from: Proximity step 2
  10. // forked from onedayitwillmake's forked from: Proximity step 1
  11. /**
  12.  * Proximity field - Step 7
  13.  * @Revision 
  14.  *         -First time using BetweenAS3!
  15.                 -the parameter, "stopOnComplete" = false, brings this spiderweb to life
  16.  * @author Mario Gonzalez
  17.  * @see http://onedayitwillmake.com/ 
  18.  */
  19. package
  20. {
  21.     
  22.     import flash.display.GradientType;
  23.     import flash.display.Graphics;
  24.     import flash.display.Shape;
  25.     import flash.display.SpreadMethod;
  26.     import flash.display.Sprite;
  27.     import flash.display.StageQuality;
  28.     import flash.events.Event;
  29.     import flash.events.MouseEvent;
  30.     import flash.geom.Matrix;
  31.     import flash.geom.Point;
  32.     
  33.     import org.libspark.betweenas3.BetweenAS3;
  34.     import org.libspark.betweenas3.easing.Back;
  35.     import org.libspark.betweenas3.easing.Sine;
  36.     import org.libspark.betweenas3.tweens.ITween;
  37.     [SWF(width="465", height="465", background="#000000")]
  38.     
  39.     public class Proximity extends Sprite
  40.     {
  41.         //Parameters 
  42.                 private var _cCount            :int = 0;
  43.                 private var _cMax            :int = 80;
  44.         //Rendering
  45.         private var _canvas            :Sprite;
  46.         public    var _canvasGraphics    :Graphics
  47.         //Reference 
  48.         public    var _lastCircle        :Circle; 
  49.         //Movement
  50.                 public static var FORCE_DEFAULT     :int = 500;
  51.                 public static var FORCE             :int = FORCE_DEFAULT;
  52.         public var _mousePressed    :Boolean = false;
  53.                 public var _mousePoint          :Point = new Point(00);
  54.         
  55.         public function Proximity()
  56.         {
  57.             stage.quality = StageQuality.LOW
  58.             addChildAt(createBG(), 0);
  59.             addChild(_canvas = new Sprite());
  60.             _canvasGraphics = _canvas.graphics;
  61.                         
  62.                         create();
  63.                                              
  64.             addEventListener(Event.ENTER_FRAME, loop);
  65.             stage.addEventListener(MouseEvent.MOUSE_DOWN, toggleMouseDown);
  66.             stage.addEventListener(MouseEvent.MOUSE_UP, toggleMouseDown);
  67.                            
  68.         }
  69.         
  70.         private function createBG():Sprite
  71.         {
  72.             var matr:Matrix = new Matrix();
  73.             matr.createGradientBox(465465, Math.PI / 200);
  74.             
  75.             var bg:Sprite = new Sprite();
  76.             bg.graphics.beginGradientFill
  77.             (
  78.                 GradientType.LINEAR, 
  79.                 [0x000021, 0x000000], //colors
  80.                 [11], //alphas
  81.                 [0255], //ratios
  82.                 matr, //matrix
  83.                 SpreadMethod.PAD
  84.             );    
  85.             
  86.             bg.graphics.drawRect(00465465);
  87.             bg.graphics.endFill();
  88.             
  89.             return bg;
  90.         }
  91.         
  92.         /**
  93.          * Main program loop
  94.          */ 
  95.         private function loop(e:Event):void
  96.         {
  97.              if(stage.mouseX == _mousePoint.x && stage.mouseY == _mousePoint.y)
  98.                 Proximity.FORCE = 0;
  99.              else
  100.                  Proximity.FORCE = Proximity.FORCE_DEFAULT
  101.                         
  102.             _mousePoint.x = stage.mouseX;
  103.             _mousePoint.y = stage.mouseY;
  104.             
  105.             draw();
  106.         }
  107.         
  108.         /**
  109.          * Creates more circles if we have not reached the maximum count
  110. #  // Time setting: 2.5sec
  111. #             BetweenAS3.tween(box1, {x: 220}, null, 2.5).play();
  112. #             
  113. #             // Easing setting: EaseOutBounce
  114. #             BetweenAS3.tween(box2, {x: 220}, null, 0.5, Bounce.easeOut).play();
  115. #             
  116. #             // Easing with parameter
  117. #             BetweenAS3.tween(box3, {x: 220}, null, 0.5, Back.easeOutWith(1.9)).play();
  118. #             
  119. #             // Delay setting: 1.0sec
  120. #             BetweenAS3.tween(box4, {x: 220}, null, 1.5, null, 1.0).play();
  121.          */ 
  122.         public function create():void
  123.         {
  124.             //if(_cCount >= _cMax) return;
  125.              
  126.             var c:Circle;
  127.                         var columns :int = 8;
  128.                         var rows    :int = 10;
  129.                         for(var ax:int = 0; ax < columns; ax++)
  130.                         {
  131.                             for (var ay:int = 0; ay < rows; ay++)
  132.                             {
  133.                                  c = new Circle(this);
  134.                                  
  135.                                  var startX:int = Math.random() * 465;
  136.                                  var startY:int = Math.random() * 10 - 5 + 15;
  137.                                  var homeX:int = ax * (475 / columns);
  138.                                  var homeY:int = 470
  139.                                  
  140.                                  addChild(c);
  141.                                 
  142.                                  var t:ITween = 
  143.                                  BetweenAS3.tween(c,
  144.                                      {_ix: homeX, x: homeX, y: homeY, _iy: homeY}, /* End values */
  145.                                      {x: startX, _ix: startX, y: startY, _iy: startY}, /* Start at */
  146.                                      Math.random() * 6 + 1/* Tween duration in seconds */
  147.                                      Sine.easeOutIn, /* Easing equation */ 
  148.                                      Math.random() * 3
  149.                                  );
  150.                                       t.stopOnComplete = false;
  151.                                       t.onPlay = c.reset;
  152.                                       t.play();
  153.                                      
  154.                                       
  155.                                  if(_lastCircle) 
  156.                                      c._prev = _lastCircle;    
  157.                                   
  158.                                   _lastCircle = c;
  159.                             }    
  160.                         }
  161.         }
  162.         
  163.         /**
  164.          * Draws the proximity field between the circles
  165.          */ 
  166.         public function draw():void
  167.         {
  168.             _canvas.graphics.clear();
  169.             _canvas.graphics.lineStyle(1, 0xffffff, 0.3);
  170.             
  171.             if(_lastCircle == nullreturn;
  172.             
  173.             _lastCircle.checkForProximity(_lastCircle._prev);
  174.             _lastCircle.move();
  175.         }
  176.         
  177.         public function toggleMouseDown(e:MouseEvent):void
  178.         {
  179.             if(_mousePressed)
  180.                 _mousePressed = false;
  181.             else
  182.                 _mousePressed = true;
  183.         }
  184.     }
  185. }
  186. import flash.display.Shape;
  187. import flash.display.Sprite;
  188. /**
  189.  * Circles that live in the feild
  190.  */
  191. class Circle extends Sprite
  192. {
  193.     private var _radius            :Number = Math.random() * 15 + 5;
  194.     private var _curveModifier    :Number    = Math.random() * 50 - 25;
  195.      public    var _isEnabled        :Boolean = false;
  196.      
  197.      public var _p            :Proximity; //reference
  198.      public var _prev        :Circle;    //Linked list style behavior
  199.     
  200.     //MOVEMENT
  201.     public static var ACC_PARAM:Number = 0.05;
  202.     public static var VELOCITY_PARAM:Number = 0.85
  203.     
  204.     public var _ix:Number;
  205.     public var _iy:Number;
  206.     public var _vx:Number = 0;
  207.     public var _vy:Number = 0;
  208.     public var _ax:Number = 0;
  209.     public var _ay:Number = 0;
  210.     /**
  211.      * Individual Circles know only the Circle created previously to their own
  212.      */
  213.     public function Circle(p:Proximity):void
  214.     {
  215.     
  216.         _p = p;
  217.         //blendMode = "add";
  218. //        graphics.beginFill(Math.random() * 255 * 255 * 255, 0.5)
  219. //        graphics.drawCircle(0, 0, _radius);
  220. //        graphics.endFill();
  221.         graphics.beginFill(0xffffff, 1)
  222.         graphics.drawCircle(001);
  223.         graphics.endFill();
  224.     }
  225.     
  226.         public function reset():void
  227.         {
  228.             _vx = 0;
  229.             _vy = 0;
  230.             _ax = 0;
  231.             _ay = 0;   
  232.         }
  233.     /**
  234.      * Check all previous circles for proximity, and do [something]
  235.      * There is no need for each circle to check the ones ahead, 
  236.      * because they've already checked against this one.
  237.      * 
  238.      * Called recursively for this circle, until the linked list reaches the first circle.
  239.      * Once it does, it calls checkForProximity on its '_prev'
  240.      * The sequence repeats until there are no more previous ones
  241.      * 
  242.      * @param tc:Circle The 'test circle' we will check against.
  243.      */ 
  244.     public function checkForProximity(tc:Circle):void
  245.     {
  246.         if(tc == nullreturn// This is the first circle created (unless error of course!)
  247.         //if(tc._isEnabled == false) { checkForProximity(tc._prev); return;};
  248.         
  249.         var d:Number = Math.sqrt((x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y));
  250.         
  251.         if(d <  90)
  252.         {
  253.             _p._canvasGraphics.moveTo(x, y);
  254.             //_p._canvasGraphics.lineTo(tc.x, tc.y);
  255.             //_p._canvasGraphics.curveTo(tc.x, tc.y);
  256.             _p._canvasGraphics.curveTo((x + tc.x) * 0.5, (y + tc.y) * 0.5 + _curveModifier, tc.x, tc.y);
  257.         }
  258.         
  259.                 //Keep checking backwards for proximity, until you reach the first circle
  260.         if(tc._prev)
  261.             checkForProximity(tc._prev);
  262.         else if(_prev) //Reached first circle. We are the last created circle, so continue the loop until we reach the first
  263.             _prev.checkForProximity(_prev._prev);
  264.     }
  265.     
  266.         /** 
  267.         * Moves the circle, initial position relative to mouse attraction/repelling force
  268.         */
  269.     public function move():void
  270.     {
  271.         //Don't let the force become too strong, by saying the distance will always be X at min
  272.         var dist:Number = Math.max(Math.sqrt((x - stage.mouseX) * (x - stage.mouseX) + (y - stage.mouseY) * (y - stage.mouseY)), 40);
  273.         var dy:Number = stage.mouseY - y;
  274.         var dx:Number = stage.mouseX - x
  275.         var angle:Number = Math.atan2(dy, dx);
  276.         var f:Number = 1 / dist * Proximity.FORCE * ((_p._mousePressed == true) ? 1 : -1);
  277.         
  278.         _ax += Math.cos(angle) * f;
  279.         _ay += Math.sin(angle) * f;
  280.         _ax += (_ix - x) * ACC_PARAM;
  281.         _ay += (_iy - y) * ACC_PARAM;
  282.         _vx = (_vx + _ax) * VELOCITY_PARAM;
  283.         _vy = (_vy + _ay) * VELOCITY_PARAM;
  284.         x += _vx;
  285.         y += _vy;
  286.         _ax = _ay = 0;
  287.         
  288.         if(_prev) //Call move on all circles
  289.             _prev.move();
  290.     }
  291.     
  292.     public function destroy():void
  293.     {
  294. //         _p._firstCircle = this;
  295.     }    
  296.     
  297.     public function enable():void
  298.     {
  299.         x = _ix = Math.random() * 10 - 5 + 15;
  300.     }
  301. }
noswf
Get Adobe Flash Player