17
May

Another variation of Sound Spectrum 1. Used bitmap data and applied some blur.

Here is the code

Actionscript:
  1. package 
  2. {
  3.     import flash.display.Bitmap;
  4.     import flash.display.BitmapData;
  5.     import flash.display.Shape;
  6.     import flash.display.Sprite;
  7.     import flash.display.StageAlign;
  8.     import flash.display.StageScaleMode;
  9.     import flash.events.Event;
  10.     import flash.events.IOErrorEvent;
  11.     import flash.events.MouseEvent;
  12.     import flash.filters.BitmapFilterQuality;
  13.     import flash.filters.BlurFilter;
  14.     import flash.geom.ColorTransform;
  15.     import flash.geom.Point;
  16.     import flash.geom.Rectangle;
  17.     import flash.media.Sound;
  18.     import flash.media.SoundChannel;
  19.     import flash.media.SoundLoaderContext;
  20.     import flash.media.SoundMixer;
  21.     import flash.net.URLRequest;
  22.     import flash.text.TextField;
  23.     import flash.text.TextFormat;
  24.     import flash.utils.ByteArray;
  25.     /**
  26.      * ...
  27.      * @author Ajay Chhaya
  28.      */
  29.     [SWF(width=512,height=200, backgroundColor="0x0", frameRate="32")]
  30.     public class SpectrumBar5 extends Sprite
  31.     {
  32.         private var txt:TextField = new TextField();
  33.         private var containerArray:Vector.<Bar> = new Vector.<Bar>;
  34.         private var snd:Sound;
  35.         private var bytes:ByteArray = new ByteArray();
  36.        
  37.         private var spectrumSprite:Sprite;
  38.         private var bitmapSource:Bitmap;
  39.         //private var bitmapPolar:Bitmap;
  40.         private var spectrumBitmapData:BitmapData;
  41.        
  42.         private var bars:int = 128;
  43.         private var strechFactor:int = 2;
  44.        
  45.         public function SpectrumBar5()
  46.         {
  47.             if (stage) init();
  48.             else addEventListener(Event.ADDED_TO_STAGE, init);
  49.            
  50.         }
  51.         private function init():void {
  52.             stage.scaleMode = StageScaleMode.NO_SCALE;
  53.             stage.align = "LT";
  54.             removeEventListener(Event.ADDED_TO_STAGE, init);
  55.            
  56.             // add information text
  57.             var tf:TextFormat = new TextFormat();
  58.             tf.font = "Arial";
  59.             txt.textColor = 0x888888;
  60.             tf.color = 0x888888;
  61.             txt.text = "Click to Start";
  62.             txt.setTextFormat(tf);
  63.             txt.x = txt.y = 10;
  64.             txt.selectable = false;
  65.             txt.width = stage.stageWidth;
  66.            
  67.             rectDraw();
  68.             addChild(txt);
  69.             //strechFactor = 256 / bars;
  70.            
  71.             stage.addEventListener(MouseEvent.MOUSE_DOWN, prepareSound);
  72.         }
  73.         private function prepareSound(e:Event = null):void {
  74.            
  75.            
  76.             stage.removeEventListener(MouseEvent.MOUSE_DOWN, prepareSound);
  77.             //mp3 downloaded from incompetech.com
  78.             playSound('Pure Attitude.mp3');
  79.            
  80.         }
  81.        
  82.         private function playSound(url:String):void
  83.         {
  84.             snd = new Sound();
  85.             var context:SoundLoaderContext = new SoundLoaderContext(0, true);
  86.             var sndReq:URLRequest = new URLRequest(url);
  87.            
  88.             snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
  89.             snd.addEventListener(Event.COMPLETE, completeHandler);
  90.            
  91.             txt.text = "Please wait for the file to be loaded.";
  92.            
  93.             snd.load(sndReq,context);
  94.             addEventListener(Event.ENTER_FRAME, onEnter);
  95.             var sndCh:SoundChannel = new SoundChannel();
  96.             sndCh = snd.play();
  97.            
  98.         }
  99.         private function errorHandler(errorEvent:IOErrorEvent):void {
  100.             txt.text = "The sound could not be loaded: " + errorEvent.text;
  101.         }
  102.         private function completeHandler(event:Event):void {               
  103.             txt.text = "File is ready.";
  104.            
  105.         }
  106.  
  107.        
  108.         private function onEnter(event:Event):void
  109.         {
  110.             SoundMixer.computeSpectrum(bytes, true, strechFactor);
  111.             var sp:Bar;
  112.             var i:int;
  113.             for (i = 0; i <bars; i++) {
  114.                 sp = containerArray[i];
  115.                 var rl:Number = bytes.readFloat();
  116.                 sp.setLevel(rl);
  117.             }
  118.            
  119.             //var sine:Number=Math.sin(angle)*RANGE;
  120.             //var cosine:Number=Math.cos(angle)*RANGE;
  121.             var blurX:int=2;
  122.             var blurY:int=8;
  123.             var filter:BlurFilter=new BlurFilter(blurX,blurY,BitmapFilterQuality.LOW);
  124.            
  125.             var rettangolo:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
  126.             var p:Point = new Point();
  127.  
  128.  
  129.             spectrumBitmapData.scroll(0, 12);
  130.             spectrumBitmapData.applyFilter(spectrumBitmapData, rettangolo, p, filter);
  131.             spectrumBitmapData.draw(spectrumSprite);
  132.            
  133.            
  134.         }
  135.  
  136.         private function rectDraw():void
  137.         {
  138.            
  139.             // create spectrumBitmapData
  140.             spectrumBitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x0);
  141.            
  142.             bitmapSource = new Bitmap();
  143.             addChild(bitmapSource);
  144.             bitmapSource.bitmapData = spectrumBitmapData;
  145.            
  146.             spectrumSprite = new Sprite();
  147.             //addChild(spectrumSprite);
  148.             var shape:Shape;
  149.             var nx:int, ny:int;
  150.             var startX:int = 0;
  151.             var startY:int = stage.stageHeight-80;
  152.             var w:int = 2;
  153.             for (var i:int = 0; i <bars; i++) {
  154.                 nx = i * (w+2);
  155.                 var b:Bar = new Bar();
  156.                 b.drawBar();
  157.                 b.x = nx + startX;
  158.                 b.y = startY;
  159.                 spectrumSprite.addChild(b);
  160.                 containerArray.push(b);
  161.             }
  162.             graphics.lineStyle(1, 0x333333, 1);
  163.             graphics.moveTo(startX, startY + w);
  164.             graphics.lineTo(nx + startX, startY + w);
  165.            
  166.             spectrumBitmapData.draw(spectrumSprite);
  167.         }
  168.         public function rgbToHex(r:int,g:int,b:int):uint
  169.         {
  170.             //trace(r, g, b);
  171.             var hex:uint = (r <<16 | g <<8 | b);
  172.             return hex;
  173.         }
  174.        
  175.     }
  176.  
  177. }
  178.  
  179. import flash.display.Bitmap;
  180. import flash.display.BitmapData;
  181. import flash.display.Sprite;
  182. import flash.display.Shape;
  183. import com.ajaychhaya.utils.Util;
  184.  
  185. class Bar extends Sprite {
  186.     public static const NUM_RECT:uint = 20;
  187.     private var boxW:int = 2;
  188.     private var gap:int = 2;
  189.     private var _rects:Vector.<Box> = new Vector.<Box>;
  190.     private var currentLevel:int = 20;
  191.    
  192.     public function drawBar():void
  193.     {
  194.         var b:Box;
  195.         var nx:int, ny:int;
  196.         var startY:int = 0;
  197.        
  198.         var r:Number = Math.random() * 255;
  199.         var g:Number = Math.random() * 255;
  200.         var bb:Number = Math.random() * 255;
  201.        
  202.         var clr:uint = Util.rgbToHex(r, g, bb);
  203.  
  204.         for (var j:int = 0; j <NUM_RECT; j++) {
  205.             ny = j * (boxW + 2);
  206.             b = new Box(clr);
  207.             b.x = nx;
  208.             b.y = startY - ny;
  209.             b.cacheAsBitmap = true;
  210.             //b.visible = false;
  211.             addChild(b);
  212.             _rects.push(b);
  213.         }
  214.  
  215.     }
  216.     public function setLevel(level:Number):void {
  217.         level = level * NUM_RECT;
  218.         currentLevel = (currentLevel <level) ? level : currentLevel - 1;
  219.         var i:int;
  220.         for (i = 0; i<NUM_RECT; i++) {
  221.             _rects[i].visible = i <currentLevel;
  222.  
  223.         }
  224.        
  225.     }
  226. }
  227.  
  228.  
  229. class Box extends Shape {
  230.     public var boxW:int = 2;
  231.     public var boxH:int = 2;
  232.     public function Box(clr:uint)
  233.     {
  234.         graphics.lineStyle(0, 0, 0);
  235.         graphics.beginFill(clr);
  236.         graphics.drawRect(0, 0, boxW, boxH);
  237.         graphics.endFill();
  238.     }
  239. }

28
Apr

Another variation of Sound Spectrum.

code:

Actionscript:
  1. package 
  2. {
  3.     import flash.display.Shape;
  4.     import flash.display.Sprite;
  5.     import flash.display.StageAlign;
  6.     import flash.display.StageScaleMode;
  7.     import flash.events.Event;
  8.     import flash.events.IOErrorEvent;
  9.     import flash.events.MouseEvent;
  10.     import flash.geom.ColorTransform;
  11.     import flash.media.Sound;
  12.     import flash.media.SoundChannel;
  13.     import flash.media.SoundLoaderContext;
  14.     import flash.media.SoundMixer;
  15.     import flash.net.URLRequest;
  16.     import flash.text.TextField;
  17.     import flash.text.TextFormat;
  18.     import flash.utils.ByteArray;
  19.     /**
  20.      * ...
  21.      * @author Ajay Chhaya
  22.      */
  23.     [SWF(width=400,height=400, backgroundColor="0x0", frameRate="32")]
  24.     public class SpectrumBar4 extends Sprite
  25.     {
  26.         private var txt:TextField = new TextField();
  27.         private var containerArray:Vector.<Bar> = new Vector.<Bar>;
  28.         private var snd:Sound;
  29.         private var bytes:ByteArray = new ByteArray();
  30.        
  31.         private var bars:int = 64;
  32.        
  33.         public function SpectrumBar4()
  34.         {
  35.             if (stage) init();
  36.             else addEventListener(Event.ADDED_TO_STAGE, init);
  37.            
  38.         }
  39.         private function init():void {
  40.             stage.scaleMode = StageScaleMode.NO_SCALE;
  41.             stage.align = "LT";
  42.             removeEventListener(Event.ADDED_TO_STAGE, init);
  43.             stage.addEventListener(MouseEvent.MOUSE_DOWN, prepareSound);
  44.             var tf:TextFormat = new TextFormat();
  45.             tf.font = "Arial";
  46.             txt.textColor = 0x888888;
  47.             tf.color = 0x888888;
  48.             txt.text = "Click to Start";
  49.             txt.setTextFormat(tf);
  50.             txt.x = txt.y = 10;
  51.             txt.selectable = false;
  52.             txt.width = stage.stageWidth;
  53.             addChild(txt);
  54.             rectDraw();
  55.         }
  56.         private function prepareSound(e:Event = null):void {
  57.            
  58.            
  59.             stage.removeEventListener(MouseEvent.MOUSE_DOWN, prepareSound);
  60.             //mp3 downloaded from incompetech.com
  61.             playSound('Pure Attitude.mp3');
  62.            
  63.            
  64.         }
  65.        
  66.         private function playSound(url:String):void
  67.         {
  68.             snd = new Sound();
  69.             var context:SoundLoaderContext = new SoundLoaderContext(0, true);
  70.             var sndReq:URLRequest = new URLRequest(url);
  71.            
  72.             snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
  73.             snd.addEventListener(Event.COMPLETE, completeHandler);
  74.            
  75.             txt.text = "Please wait for the file to be loaded.";
  76.            
  77.             snd.load(sndReq,context);
  78.  
  79.             var sndCh:SoundChannel = new SoundChannel();
  80.             sndCh = snd.play();
  81.            
  82.             addEventListener(Event.ENTER_FRAME, onEnter);
  83.            
  84.         }
  85.         private function errorHandler(errorEvent:IOErrorEvent):void {
  86.             txt.text = "The sound could not be loaded: " + errorEvent.text;
  87.         }
  88.         private function completeHandler(event:Event):void {               
  89.             txt.text = "";
  90.            
  91.         }
  92.         private function onEnter(event:Event):void
  93.         {
  94.             SoundMixer.computeSpectrum(bytes, false, 3);
  95.             var sp:Bar;
  96.             var i:int;
  97.             for (i = 0; i <bars; i++) {
  98.                 sp = containerArray[i];
  99.                 var rl:Number = bytes.readFloat();
  100.                 sp.setLevel(rl);
  101.             }
  102.            
  103.         }
  104.        
  105.         private function rectDraw():void
  106.         {
  107.             var shape:Shape;
  108.             var nx:int, ny:int;
  109.             var startX:int = stage.stageWidth/2;
  110.             var startY:int = stage.stageHeight/2;
  111.             var w:int = 2;
  112.             var rot:Number = 360 / bars;
  113.             for (var i:int = 0; i <bars; i++) {
  114.                 nx = i * (w+2);
  115.                 var b:Bar = new Bar();
  116.                 b.drawBar();
  117.                 b.x = startX;
  118.                 b.y = startY;
  119.                 b.rotation = rot*i;
  120.                 addChild(b);
  121.                 containerArray.push(b);
  122.             }
  123.         }
  124.         public function rgbToHex(r:int,g:int,b:int):uint
  125.         {
  126.             var hex:uint = (r <<16 | g <<8 | b);
  127.             return hex;
  128.         }
  129.        
  130.         private function onPlaybackComplete(event:Event):void
  131.         {
  132.             removeEventListener(Event.ENTER_FRAME, onEnter);
  133.         }
  134.        
  135.     }
  136.  
  137. }
  138.  
  139. import flash.display.Bitmap;
  140. import flash.display.BitmapData;
  141. import flash.display.Sprite;
  142. import flash.display.Shape;
  143. import com.ajaychhaya.utils.Util;
  144.  
  145. class Bar extends Sprite {
  146.     public static const NUM_RECT:uint = 20;
  147.     private var boxW:int = 2;
  148.     private var boxH:int = 6;
  149.     private var gap:int = 2;
  150.     private var _rects:Vector.<Box> = new Vector.<Box>;
  151.     private var currentLevel:int = NUM_RECT;
  152.    
  153.     public function drawBar():void
  154.     {
  155.         var b:Box;
  156.         var nx:int, ny:int;
  157.         var startY:int = 0;
  158.        
  159.         var r:Number = Math.random() * 255;
  160.         var g:Number = Math.random() * 255;
  161.         var bb:Number = Math.random() * 255;
  162.        
  163.         var clr:uint = Util.rgbToHex(r, g, bb);
  164.  
  165.         for (var j:int = 0; j <NUM_RECT; j++) {
  166.             ny = j * (boxH + 4);
  167.             b = new Box(clr);
  168.             b.x = nx;
  169.             b.y = startY + ny;
  170.             b.cacheAsBitmap = true;
  171.             //b.visible = false;
  172.             addChild(b);
  173.             _rects.push(b);
  174.         }
  175.  
  176.     }
  177.     public function setLevel(level:Number):void {
  178.         //level = Math.abs(level * NUM_RECT);
  179.         level = level * NUM_RECT;
  180.         currentLevel = (currentLevel <level) ? level : currentLevel - 1;
  181.         var i:int;
  182.         for (i = 0; i<NUM_RECT; i++) {
  183.             _rects[i].visible = i <currentLevel;
  184.  
  185.         }
  186.        
  187.     }
  188. }
  189.  
  190.  
  191. class Box extends Shape {
  192.     private var boxW:int = 2;
  193.     private var boxH:int = 6;
  194.     public function Box(clr:uint)
  195.     {
  196.         graphics.lineStyle(0, 0, 0);
  197.         graphics.beginFill(clr);
  198.         graphics.drawRect(0, 0, boxW, boxH);
  199.         //graphics.drawCircle(0, 0, boxW);
  200.         graphics.endFill();
  201.     }
  202. }

28
Apr

After a long time I had some time to experiment. I played with SoundMixer computeSpectrum. following is a very basic sound spectrum. click to play. it may will take some time to load the sound. enjoy!

Sound is downloaded from http://incompetech.com

here is the code.

Actionscript:
  1. package 
  2. {
  3.     import flash.display.Shape;
  4.     import flash.display.Sprite;
  5.     import flash.display.StageAlign;
  6.     import flash.display.StageScaleMode;
  7.     import flash.events.Event;
  8.     import flash.events.IOErrorEvent;
  9.     import flash.events.MouseEvent;
  10.     import flash.geom.ColorTransform;
  11.     import flash.media.Sound;
  12.     import flash.media.SoundChannel;
  13.     import flash.media.SoundLoaderContext;
  14.     import flash.media.SoundMixer;
  15.     import flash.net.URLRequest;
  16.     import flash.text.TextField;
  17.     import flash.text.TextFormat;
  18.     import flash.utils.ByteArray;
  19.     /**
  20.      * ...
  21.      * @author Ajay Chhaya
  22.      */
  23.     [SWF(width=512,height=200, backgroundColor="0x0", frameRate="32")]
  24.     public class SpectrumBar3 extends Sprite
  25.     {
  26.         private var txt:TextField = new TextField();
  27.         private var containerArray:Vector.<Bar> = new Vector.<Bar>;
  28.         private var snd:Sound;
  29.         private var bytes:ByteArray = new ByteArray();
  30.        
  31.         private var bars:int = 128;
  32.        
  33.         public function SpectrumBar3()
  34.         {
  35.             if (stage) init();
  36.             else addEventListener(Event.ADDED_TO_STAGE, init);
  37.            
  38.         }
  39.         private function init():void {
  40.             stage.scaleMode = StageScaleMode.NO_SCALE;
  41.             stage.align = "LT";
  42.             removeEventListener(Event.ADDED_TO_STAGE, init);
  43.             stage.addEventListener(MouseEvent.MOUSE_DOWN, prepareSound);
  44.             var tf:TextFormat = new TextFormat();
  45.             tf.font = "Arial";
  46.             txt.textColor = 0x888888;
  47.             tf.color = 0x888888;
  48.             txt.text = "Click to Start";
  49.             txt.setTextFormat(tf);
  50.             txt.x = txt.y = 10;
  51.             txt.selectable = false;
  52.             txt.width = stage.stageWidth;
  53.             addChild(txt);
  54.             rectDraw();
  55.         }
  56.         private function prepareSound(e:Event = null):void {
  57.            
  58.            
  59.             stage.removeEventListener(MouseEvent.MOUSE_DOWN, prepareSound);
  60.             //mp3 downloaded from incompetech.com
  61.             playSound('Pure Attitude.mp3');
  62.            
  63.            
  64.         }
  65.        
  66.         private function playSound(url:String):void
  67.         {
  68.             snd = new Sound();
  69.             var context:SoundLoaderContext = new SoundLoaderContext(0, true);
  70.             var sndReq:URLRequest = new URLRequest(url);
  71.            
  72.             snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
  73.             snd.addEventListener(Event.COMPLETE, completeHandler);
  74.            
  75.             txt.text = "Please wait for the file to be loaded.";
  76.            
  77.             snd.load(sndReq,context);
  78.            
  79.            
  80.         }
  81.         private function errorHandler(errorEvent:IOErrorEvent):void {
  82.             txt.text = "The sound could not be loaded: " + errorEvent.text;
  83.         }
  84.         private function completeHandler(event:Event):void {               
  85.             txt.text = "File is ready.";
  86.             addEventListener(Event.ENTER_FRAME, onEnter);
  87.             var sndCh:SoundChannel = new SoundChannel();
  88.             sndCh = snd.play();
  89.         }
  90.  
  91.        
  92.         private function onEnter(event:Event):void
  93.         {
  94.             SoundMixer.computeSpectrum(bytes, false, 1);
  95.             var sp:Bar;
  96.             var i:int;
  97.             for (i = 0; i <bars; i++) {
  98.                 sp = containerArray[i];
  99.                 var rl:Number = bytes.readFloat();
  100.                 sp.setLevel(rl);
  101.             }
  102.            
  103.         }
  104.  
  105.         private function rectDraw():void
  106.         {
  107.             var shape:Shape;
  108.             var nx:int, ny:int;
  109.             var startX:int = 0;
  110.             var startY:int = stage.stageHeight-50;
  111.             var w:int = 2;
  112.             for (var i:int = 0; i <bars; i++) {
  113.                 nx = i * (w+2);
  114.                 var b:Bar = new Bar();
  115.                 b.drawBar();
  116.                 b.x = nx + startX;
  117.                 b.y = startY;
  118.                 addChild(b);
  119.                 containerArray.push(b);
  120.             }
  121.             graphics.lineStyle(1, 0x333333, 1);
  122.             graphics.moveTo(startX, startY + w);
  123.             graphics.lineTo(nx + startX, startY + w);
  124.         }
  125.         public function rgbToHex(r:int,g:int,b:int):uint
  126.         {
  127.             //trace(r, g, b);
  128.             var hex:uint = (r <<16 | g <<8 | b);
  129.             return hex;
  130.         }
  131.        
  132.     }
  133.  
  134. }
  135.  
  136. import flash.display.Bitmap;
  137. import flash.display.BitmapData;
  138. import flash.display.Sprite;
  139. import flash.display.Shape;
  140. import com.ajaychhaya.utils.Util;
  141.  
  142. class Bar extends Sprite {
  143.     public static const NUM_RECT:uint = 20;
  144.     private var boxW:int = 2;
  145.     private var gap:int = 2;
  146.     private var _rects:Vector.<Box> = new Vector.<Box>;
  147.     private var currentLevel:int = 20;
  148.    
  149.     public function drawBar():void
  150.     {
  151.         var b:Box;
  152.         var nx:int, ny:int;
  153.         var startY:int = 0;
  154.        
  155.         var r:Number = Math.random() * 255;
  156.         var g:Number = Math.random() * 255;
  157.         var bb:Number = Math.random() * 255;
  158.        
  159.         var clr:uint = Util.rgbToHex(r, g, bb);
  160.  
  161.         for (var j:int = 0; j <NUM_RECT; j++) {
  162.             ny = j * (boxW + 2);
  163.             b = new Box(clr);
  164.             b.x = nx;
  165.             b.y = startY - ny;
  166.             b.cacheAsBitmap = true;
  167.             //b.visible = false;
  168.             addChild(b);
  169.             _rects.push(b);
  170.         }
  171.  
  172.     }
  173.     public function setLevel(level:Number):void {
  174.         level = level * NUM_RECT;
  175.         currentLevel = (currentLevel <level) ? level : currentLevel - 1;
  176.         var i:int;
  177.         for (i = 0; i<NUM_RECT; i++) {
  178.             _rects[i].visible = i <currentLevel;
  179.  
  180.         }
  181.        
  182.     }
  183. }
  184.  
  185.  
  186. class Box extends Shape {
  187.     private var boxW:int = 2;
  188.     public function Box(clr:uint)
  189.     {
  190.         graphics.lineStyle(0, 0, 0);
  191.         graphics.beginFill(clr);
  192.         graphics.drawRect(0, 0, boxW, boxW);
  193.         graphics.endFill();
  194.     }
  195. }

Today I came across a very unusual problem. While compiling an old Flash CS3 project in Flash CS4, Compiler thew an error saying "1044: Interface method {Methodname} in namespace {InterfaceName} not implemented by class {ClassName}." while in CS3 the same project complied without any problem. Class was implementing an Interface and an internal Class was defined in the same .as file. After some debugging I found that if you Implement an Interface and defined an Internal class within same file, then CS4 will not compile the FLA and will throw the error. Here is an example you can try in CS4.

create an interface IFoo with function definition test. create a Class Foo which implements IFoo and defined function test.

Class Foo

Actionscript:
  1. package {
  2. public class Foo implements IFoo
  3. {
  4. public function Foo(){};
  5. public function test():void{};
  6. }
  7. }
  8. internal class myInternalClass{};

In your FLA just write

Actionscript:
  1. var a:Foo = new Foo();

If you try to compile this file, compiler will throw en error
"1044: Interface method test in namespace IFoo not implemented by class Foo." If you remove the internal Class definition

Actionscript:
  1. internal class myInternalClass{};

Fla will compile without any problem.

This is a bug in CS4, so make sure that if your Class is implementing an Interface and need to use an internal class, declare that internal class in a separate class file .

Yesterday when I posted about Flash in Gmail I didn't mentioned what the problem was. Here is my assumption on what the problem was and what could have caused that problem.

On the help page, it was mentioned that attachment functionality required Flash player 8 or greater, and if you have Flash player 10 installed then set the option for normal attachment in the settings. I have Flash player 10 installed, so I opted for basic attachment option in settings and attached the files.

So the question is, why it didn't worked with Flash player 10?

Because of a new security enhancements in Flash player 10.  In previous versions of the Flash Player, you could pro programmatically call the FileReference.browse() method to open a file browser dialog window which enabled users to locate a file on their system so that it could be uploaded to a server. In Flash Player 10 you can no longer spawn this dialog window programmatically and it must be initiated by a user click. you can read more about this here on Lee's blog. To overcome this issue either create the HTML upload button in Flash rather than HTML or  overlay a transparent SWF button over the HTML content.

So I assume that in Gmail, "attach a file"button was in HTM and it was invoking browse method dynamically within a hidden swf object, which was throwing exception. I said Gmail was using.. because when in the evening when I went back to check the error, I set the settings to advanced and clicked on attach a file it didn't gave me any error, and when I checked, attach a file button was in Flash. So I assume that they have placed the button within swf or they have overlayed the swf over the button.

Today I was attaching a file in Gmail and it was failing. I was wondering what the problem is when I saw a help button next to the attach button. I clicked it and it lead me to help page which said you need Flash Player to upload and you can change this advanced option in settings.

On setting page I found the following option

" - See progress bars when attaching files to messages, and attach multiple files at once. Requires flash. Learn more "

Only then I realized that to show attachment progress, Gmail is using Flash. I checked, "Attach file" is a Flash button. It is amazing to see how Google used flash to improve the user experience.

And there are many who still says Flash is not user friendly :)

Update: I have posted more details here

Have you already switched to AS3 ?  Are you still working with XML in AS2?

Look at this tutorial about XML and AS3 and see what you are missing.

There was a requirement for a text editor in one of our current Flex 2 project. But after too much of efforts we came to conclusion that to develop a decent text editor without any bug is next to impossible. As most of you might be aware of a few bugs with <img> tag in Flash textfield as explained below.

  • Whenever textfield renders an image tag it generates a textformat object with font size of 2.  Because of this, if you place the cursor exactly next to image and type, text will have font size 2.
  • textHeight property is buggy if you insert the Image at the end of text. Because of this, scrollbar wont work properly.
  • If you delete the image tag from the text of textfield it does not refresh imedietly. It refreshes after you change other text content. You can see a blank white patch where the image was, and text will be wrapped around that blank space, if you edit the text later,  that blank space will be removed.

You can see listing of other bugs here on play.ground blog

Hopefully this issue is solved in Flash player 10 or we should overcome this issue with low level API of textfield object.

13
Dec

Just downloaded Bee, an Air application, and posting this post from Bee. I'm really excited about the Air. Lets see If I can come up within next few days.

23
Nov

Welcome to my personal blog. I'm Ajay Chhaya, A multimedia developer from Mumbai-India. I'll post my thoughts on Web and Multimedia Development . Most of the blogs will be Flash platform related as  I work on those technologies .