Preloading unlimited numbers of images

var _xmlLoader:URLLoader = null;
var _xml:XML = null;    
var _counter:int = 0;    
var _list:Array = null;    
var _loader:Loader = null;    
var _imgList:Array = null;

function Init():void    
{     
    _xmlLoader = new URLLoader();     	
   _xmlLoader.load(new URLRequest("resources.xml"));
   _xmlLoader.addEventListener(Event.COMPLETE, Complete, false, 0, true);    
}        

function Complete($e:Event):void    
{     	
    _xmlLoader.removeEventListener(Event.COMPLETE, Complete);    	
    _xmlLoader = null;     	
    _xml = new XML($e.target.data);    
	    	
    _list = [];    	
    _imgList = [];    	
   _loader = new Loader();    	
    	 
   for(var i:int=0;i<_xml.image.length();i++)    	 
   {    		
        _list.push(_xml.image[i].@path);    	 
   }     	

    LoadImage();    
}        

function LoadImage():void    
{      
    _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, Progress, false, 0 ,true); 
    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ImageLoaded, false, 0 ,true);
   _loader.load(new URLRequest(_list[_counter]));    
}       

function Progress($e:ProgressEvent):void   
{      
    trace("Progress: " + (_counter+1).toString() + " / " +  (_xml.image.length()).toString() + " - " + (Math.ceil($e.bytesLoaded/$e.bytesTotal *100)).toString() + " %" );    
}        

function ImageLoaded($e:Event):void   
{     	
    _loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, Progress);     
    _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, Complete);    	    	
    _imgList.push(new Sprite());    	
    _imgList[_imgList.length -1].addChild($e.target.content);  
   _loader.unload();     	
   _counter++;    	    	 
   if(_counter <= _xml.image.length() - 1)    	
  {    		
      LoadImage();    	 
   }else{    		
     _loader = null;    		
     _list = null;    		
     DisplayImages();    	 
   }         
}        

function DisplayImages():void    
{    	 
    for(var i:uint = 0; i&lt;_imgList.length;i++)    	
   {    	  
         addChild(_imgList[i]);    	 
    }    
}        

Init();

And this is how the XML should look like

   <?xml version="1.0" encoding="utf-8" ?> 
    <tutorial> 
    	<image path="images/image_1.jpg"/>
    	<image path="images/image_2.jpg"/>
    	<image path="images/image_3.jpg"/>
    </tutorial> 
Advertisements

Artist XML Image / Photo Gallery

Artist XML Image / Photo Gallery

Artist XML Image / Photo Gallery

Full browser based image / photo gallery with categories perfect for both experienced or casual photographers and artists.
Everything is set from an external XML file making it easy to update and maintain.

Key Features:

XML driven content making it easy to customize, update and maintain
FlashVars support ( for the XML configuration file )
Unlimited number of categories
Unlimited number of images / photos
HTML formatting for description text
– background image for each category
– OOP code.
small size swf: 24 kb

Customization

– the content through the XML file
– the text and the color of the gallery title
– the color of the footer text label
– the color of the thumb border when unselected
– the color of the thumb border when selected
– the color of the text label of thumb’s title
– close button color
– the color of the navigation button when selected
– the color of the navigation button when unselected
– the color of the info button
– the color of the title in the full image view mode

————————————————————–

See the component in action here

You can buy it at full price from that site
or
message me at cilibiu_dragos@yahoo.com for a half of it’s price

 

Resize Background Image with Correct Aspect Ratio in Actionscript 3.0

var _img:Loader = null;
var _picW:Number = 0;
var _picH:Number = 0;

stage.scaleMode    = StageScaleMode.NO_SCALE;
stage.align        = StageAlign.TOP_LEFT;

function LoadBackGround($path:String):void
{
    _img = new Loader();
    _img.load(new URLRequest($path));
   _img.contentLoaderInfo.addEventListener(Event.COMPLETE, Loaded, false, 0, true);
}

function Loaded($e:Event):void
{
    _img.contentLoaderInfo.removeEventListener(Event.COMPLETE, Loaded);

   _picW = _img.height / _img.width;
   _picH = _img.width / _img.height;

   addChild(_img);

   stage.addEventListener(Event.RESIZE, ProportionalScale, false, 0, true);
   ProportionalScale();
}

function ProportionalScale($e:Event=null):void
{
    var $sw:Number    = stage.stageWidth;
    var $sh:Number    = stage.stageHeight;
    var $scale:Number = 0;

if (($sh / $sw) > (_img.height / _img.width))
{
    $scale = _img.width / _img.height;
    _img.height = $sh;
    _img.width = $sh * $scale;

} else {
    $scale =_img.height / _img.width;
   _img.width =  $sw;
   _img.height = $sw * $scale;
}

_img.x = ($sw - _img.width) / 2;
_img.y = ($sh - _img.height) / 2;
}

LoadBackGround("image.jpg");

Grey XML Image / Photo Gallery

Grey XML Image / Photo Gallery

Grey XML Image / Photo Gallery

Full browser based grid based imagephoto gallery with categories perfect for both experienced or casual photographers and artists.
Everything is set from an external XML file making it easy to update and maintain.

Key Features:

– XML driven content making it easy to customize, update and maintain
– FlashVars support ( for the setup Xml )
– Unlimited number of categories
– Unlimited number of images / photos
– HTML formatting for description
– Zooming & panning on large images
– Ambient music
– OOP code.

————————————————————–

See the component in action here

You can buy it at full price from that site
or
message me at cilibiu_dragos@yahoo.com for a half of it’s price

Smallest Flash Tween Engines

When it comes to tweening sometimes size does matter.

In many of my projects I used TweenMax or Caurina classes and every one of them are good but sometimes when I need some simple tweens the size they are adding to the project are quite big.

Luckly I can choose from many tween projects and some of them ar e quite interesting.

The next tween engines concentrate to be micro and provide nice features while trying to be so small

ByteTween [ 1.7kb ]

TweenLite [ 2.6kb ]

GTweeny [ 3kb ]

TweensyZero [2.9kb ]