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

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

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


FORKED
  1. // forked from a8085's Bubble Sort
  2. // write as3 code here..
  3. package
  4. {
  5.     import flash.display.*;
  6.     import flash.events.*;
  7.     import flash.media.*;
  8.     import flash.net.*;
  9.     import flash.utils.*;
  10.     public class BubbleSort extends Sprite
  11.     {   
  12.         //並び替えを行うアイテムを入れておく配列  
  13.         private var items:Array = new Array();
  14.         
  15.         //並び替えを行うタイマー
  16.         private var sortTimer:Timer = new Timer(100);
  17.         
  18.         //配色
  19.         private var colorSet:Array = [0xff7f7f, 0xff7fbf, 0xff7fff, 0xbf7fff, 0x7f7fff, 0x7fbfff, 0x7fffff, 0x7fffbf, 0x7fff7f, 0xbff7f, 0xffff7f, 0xffbf7f]
  20.         private var colorIndex:uint = 0;
  21.         
  22.         //並び替え用の変数
  23.         private var position:int;
  24.         private var lastPosition:int;
  25.         public function BubbleSort():void
  26.         {
  27.             super();
  28.             
  29.             var WIDTH:uint = 456;
  30.             var HEIGHT:uint = 456;
  31.             //var HEIGHT:uint = 64;
  32.             
  33.             var itemX:uint = 2;
  34.             var itemY:uint = 2;
  35.             
  36.             var target:uint = 0;
  37.             //アイテムの配置
  38.             while(itemY < HEIGHT){
  39.                 while(itemX < WIDTH){
  40.                     var item:NumberItem = new NumberItem(Math.round(Math.random() * 100));
  41.                     item.x = itemX;
  42.                     item.y = itemY;
  43.                     this.addChild(item);
  44.                     items.push(item);
  45.     
  46.                     itemX += 36;
  47.                 }
  48.                 itemX = 3;
  49.                 itemY = item.y + 36;
  50.             }
  51.             
  52.             //並び替え変数の初期化
  53.             position = 0;
  54.             lastPosition = items.length -1;
  55.             
  56.             //並び替え開始
  57.             sortTimer.addEventListener(TimerEvent.TIMER, bubbleSort);
  58.             sortTimer.start();
  59.             
  60.         }
  61.         
  62.         //バブルソート
  63.         private function bubbleSort(e:TimerEvent):void
  64.         {
  65.             if(position < lastPosition){
  66.                 position++;
  67.             }
  68.             if( (items[position - 1as NumberItem).value > (items[position] as NumberItem).value ){
  69.                 this.swap(position - 1, position);
  70.             }
  71.             if(position == lastPosition){
  72.                 lastPosition--;
  73.                 position = 0;
  74.             }
  75.             if(lastPosition == 0){
  76.                 sortTimer.stop();
  77.             }
  78.         }
  79.         
  80.         //スワップ
  81.         private function swap(index1:Number, index2:Number):void{
  82.             var tmp:Number = (items[index1] as NumberItem).value;
  83.             (items[index1] as NumberItem).value = (items[index2] as NumberItem).value;
  84.             (items[index2] as NumberItem).value = tmp;
  85.             var color:Number = nextColor();
  86.             (items[index1] as NumberItem).illuminate(color);
  87.             (items[index2] as NumberItem).illuminate(color);
  88.         }
  89.         //配色取得
  90.         private function nextColor():Number
  91.         {
  92.             if(colorSet.length - 1 <= colorIndex){
  93.                 colorIndex = 0;
  94.             }else{
  95.                 colorIndex++;
  96.             }
  97.             
  98.             return colorSet[colorIndex];
  99.         }
  100.     }
  101. }
  102. import flash.display.*;
  103. import flash.text.*;
  104. import flash.filters.*;
  105. import flash.utils.*;
  106. import flash.events.*;
  107. //アイテムクラス
  108. class NumberItem extends Sprite
  109. {
  110.         
  111.     private var itemText:TextField = new TextField();
  112.     private var textFormat:TextFormat = new TextFormat();
  113.     private var innerCircle:Sprite = new Sprite();
  114.     private var timer:Timer = new Timer(10);
  115.     public function NumberItem(number:Number):void
  116.     {
  117.         var dsFilter:DropShadowFilter = new DropShadowFilter(0.545, 0x666666);
  118.         this.filters = [dsFilter];
  119.          
  120.          this.graphics.beginFill(0xFFFFFF);
  121.         this.graphics.drawCircle(161616);
  122.         this.graphics.endFill();
  123.          
  124.         innerCircle.graphics.beginFill(0xFFFFFF);
  125.         innerCircle.graphics.drawCircle(161616);
  126.         innerCircle.graphics.endFill();
  127.         this.addChild(innerCircle);
  128.         textFormat.size = 14;
  129.         textFormat.align = TextFormatAlign.CENTER;
  130.         textFormat.bold = true;
  131.     
  132.         itemText = new TextField();
  133.         itemText.width = 32;
  134.         itemText.y = 5;
  135.         this.value = number;
  136.         this.updateTextFormat();
  137.         this.addChild(itemText);        
  138.         timer.addEventListener(TimerEvent.TIMER, timerHandler);
  139.     }
  140.     //文字のスタイルを設定
  141.     private function updateTextFormat():void
  142.     {
  143.         itemText.setTextFormat(textFormat);
  144.     }
  145.     //ハイライト処理。ハイライト後、フェードアウト
  146.     public function illuminate(color:Number):void
  147.     {
  148.         timer.reset();
  149.         
  150.         innerCircle.alpha = 1;
  151.         innerCircle.graphics.clear();
  152.         
  153.         innerCircle.graphics.beginFill(color);
  154.         innerCircle.graphics.drawCircle(161616);
  155.         innerCircle.graphics.endFill();
  156.         this.updateTextFormat();
  157.         
  158.         timer.start();
  159.     }
  160.     
  161.     //色のフェードアウト処理
  162.     private function timerHandler(e:TimerEvent):void
  163.     {
  164.         //trace(innerCircle.alpha);
  165.         innerCircle.alpha -= 0.1;
  166.         if(innerCircle.alpha < 0)
  167.         {
  168.             trace("stop");
  169.             innerCircle.graphics.clear()
  170.             innerCircle.alpha = 1;
  171.             innerCircle.graphics.beginFill(0xFFFFFF);
  172.             innerCircle.graphics.drawCircle(161616);
  173.             innerCircle.graphics.endFill();
  174.             timer.reset();
  175.         }
  176.     }
  177.     
  178.     public function get value():Number
  179.     {
  180.         return Number(itemText.text);
  181.     }
  182.     
  183.     public function set value(number:Number):void
  184.     {
  185.         this.itemText.text = number.toString();
  186.     }
  187. }
noswf
  1. // forked from a8085's Bubble Sort
  2. // write as3 code here..
  3. package
  4. {
  5.     import flash.display.*;
  6.     import flash.events.*;
  7.     import flash.media.*;
  8.     import flash.net.*;
  9.     import flash.utils.*;
  10.     public class BubbleSort extends Sprite
  11.     {   
  12.         //並び替えを行うアイテムを入れておく配列  
  13.         private var items:Array = new Array();
  14.         
  15.         //並び替えを行うタイマー
  16.         private var sortTimer:Timer = new Timer(1);
  17.         
  18.         //配色
  19.         private var colorSet:Array = [0xff7f7f, 0xff7fbf, 0xff7fff, 0xbf7fff, 0x7f7fff, 0x7fbfff, 0x7fffff, 0x7fffbf, 0x7fff7f, 0xbff7f, 0xffff7f, 0xffbf7f]
  20.         private var colorIndex:uint = 0;
  21.         
  22.         //並び替え用の変数
  23.         private var position:int;
  24.         private var lastPosition:int;
  25.         public function BubbleSort():void
  26.         {
  27.             super();
  28.             
  29.             var WIDTH:uint = 456;
  30.             var HEIGHT:uint = 456;
  31.             //var HEIGHT:uint = 64;
  32.             
  33.             var itemX:uint = 2;
  34.             var itemY:uint = 2;
  35.             
  36.             var target:uint = 0;
  37.             //アイテムの配置
  38.             while(itemY < HEIGHT){
  39.                 while(itemX < WIDTH){
  40.                     var item:NumberItem = new NumberItem(Math.round(Math.random() * 100));
  41.                     item.x = itemX;
  42.                     item.y = itemY;
  43.                     this.addChild(item);
  44.                     items.push(item);
  45.     
  46.                     itemX += 36;
  47.                 }
  48.                 itemX = 2;
  49.                 itemY = item.y + 36;
  50.             }
  51.             
  52.             //並び替え変数の初期化
  53.             position = 0;
  54.             lastPosition = items.length -1;
  55.             
  56.             //並び替え開始
  57.             sortTimer.addEventListener(TimerEvent.TIMER, bubbleSort);
  58.             sortTimer.start();
  59.             
  60.         }
  61.         
  62.         //バブルソート
  63.         private function bubbleSort(e:TimerEvent):void
  64.         {
  65.             if(position < lastPosition){
  66.                 position++;
  67.             }
  68.             if( (items[position - 1as NumberItem).value > (items[position] as NumberItem).value ){
  69.                 this.swap(position - 1, position);
  70.             }
  71.             if(position == lastPosition){
  72.                 lastPosition--;
  73.                 position = 0;
  74.             }
  75.             if(lastPosition == 0){
  76.                 sortTimer.stop();
  77.             }
  78.         }
  79.         
  80.         //スワップ
  81.         private function swap(index1:Number, index2:Number):void{
  82.             var tmp:Number = (items[index1] as NumberItem).value;
  83.             (items[index1] as NumberItem).value = (items[index2] as NumberItem).value;
  84.             (items[index2] as NumberItem).value = tmp;
  85.             var color:Number = nextColor();
  86.             (items[index1] as NumberItem).illuminate(color);
  87.             (items[index2] as NumberItem).illuminate(color);
  88.         }
  89.         //配色取得
  90.         private function nextColor():Number
  91.         {
  92.             if(colorSet.length - 1 <= colorIndex){
  93.                 colorIndex = 0;
  94.             }else{
  95.                 colorIndex++;
  96.             }
  97.             
  98.             return colorSet[colorIndex];
  99.         }
  100.     }
  101. }
  102. import flash.display.*;
  103. import flash.text.*;
  104. import flash.filters.*;
  105. import flash.utils.*;
  106. import flash.events.*;
  107. //アイテムクラス
  108. class NumberItem extends Sprite
  109. {
  110.         
  111.     private var itemText:TextField = new TextField();
  112.     private var textFormat:TextFormat = new TextFormat();
  113.     private var innerCircle:Sprite = new Sprite();
  114.     private var timer:Timer = new Timer(10);
  115.     public function NumberItem(number:Number):void
  116.     {
  117.         var dsFilter:DropShadowFilter = new DropShadowFilter(0.545, 0x666666);
  118.         this.filters = [dsFilter];
  119.          
  120.          this.graphics.beginFill(0xFFFFFF);
  121.         this.graphics.drawCircle(161616);
  122.         this.graphics.endFill();
  123.          
  124.         innerCircle.graphics.beginFill(0xFFFFFF);
  125.         innerCircle.graphics.drawCircle(161616);
  126.         innerCircle.graphics.endFill();
  127.         this.addChild(innerCircle);
  128.         textFormat.size = 14;
  129.         textFormat.align = TextFormatAlign.CENTER;
  130.         textFormat.bold = true;
  131.     
  132.         itemText = new TextField();
  133.         itemText.width = 32;
  134.         itemText.y = 5;
  135.         this.value = number;
  136.         this.updateTextFormat();
  137.         this.addChild(itemText);        
  138.         timer.addEventListener(TimerEvent.TIMER, timerHandler);
  139.     }
  140.     //文字のスタイルを設定
  141.     private function updateTextFormat():void
  142.     {
  143.         itemText.setTextFormat(textFormat);
  144.     }
  145.     //ハイライト処理。ハイライト後、フェードアウト
  146.     public function illuminate(color:Number):void
  147.     {
  148.         timer.reset();
  149.         
  150.         innerCircle.alpha = 1;
  151.         innerCircle.graphics.clear();
  152.         
  153.         innerCircle.graphics.beginFill(color);
  154.         innerCircle.graphics.drawCircle(161616);
  155.         innerCircle.graphics.endFill();
  156.         this.updateTextFormat();
  157.         
  158.         timer.start();
  159.     }
  160.     
  161.     //色のフェードアウト処理
  162.     private function timerHandler(e:TimerEvent):void
  163.     {
  164.         //trace(innerCircle.alpha);
  165.         innerCircle.alpha -= 0.1;
  166.         if(innerCircle.alpha < 0)
  167.         {
  168.             trace("stop");
  169.             innerCircle.graphics.clear()
  170.             innerCircle.alpha = 1;
  171.             innerCircle.graphics.beginFill(0xFFFFFF);
  172.             innerCircle.graphics.drawCircle(161616);
  173.             innerCircle.graphics.endFill();
  174.             timer.reset();
  175.         }
  176.     }
  177.     
  178.     public function get value():Number
  179.     {
  180.         return Number(itemText.text);
  181.     }
  182.     
  183.     public function set value(number:Number):void
  184.     {
  185.         this.itemText.text = number.toString();
  186.     }
  187. }
noswf
Get Adobe Flash Player