March 25th, 2009
During my last jobs I wrote a queue loader class that stores all loaded files for future requests.
DataLib
Overview:
-Static
Since it’s a static class, any loaded file can be used from any parto of the app, even from external SWF files.
-Load queue
Any file must be add to a load queue passing the url and type of file to be loaded. The file can be added at the end of the queue or in a especific position.
DataLib.addItem("file.swf", DataLib.TYPE_SWF);
DataLib.addItemAt("file.png", 0, DataLib.TYPE_PNG);
DataLib.addItem("file.wav", DataLib.TYPE_BINARY);
Also is possible get the load queue.
var queue:Array = DataLib.queue;
To start loading you must call DataLib.load()
Also it’s possible to pause, resume and close the loading.
DataLib.pause();
DataLib.resume();
DataLib.close();
-Data storage
Every load file is stored for future requisitions. If necessary, files can be deleted freeing memory. Get loaded files using it’s URL.
var image:Bitmap = DataLib.lib[fileURL].data;
addChild(image);
DataLib.removeItem(fileURL);
-Custom Events
Custom Events cam be added to follow the loading. You can add an event in the class or in a especific item.
*Remember to remove all events from the class to prevent conflicts with other loadings.
DataLib.addItemAt("file.png", 0, DataLib.TYPE_PNG).addEventListener(DataLibEvent.PROGRESS, onItemProgress);
DataLib.lib["file.xml"].addEventListener(DataLibEvent.COMPLETE, onItemComplete);
DataLib.addEventListener(DataLibEvent.COMPLETE, onComplete);
DataLib.load();
function onItemProgress(e:Event):void{
trace(Math.floor(e.bytesLoaded*100/e.bytesTotal)+"%");
}
function onItemComplete(e:Event):void{
trace(e.data);
}
function onComplete(e:Event):void{
addChild(DataLib.lib["file.png"].data);
}
-JPG, GIF, PNG, SWF, XML and BINARY
These are the supported files. You can get embed classes in SWF loaded files using the main movie application domain.
DataLib.addItem("asset.swf", DataLib.TYPE_SWF);
addChild(DataLib.lib["asset.swf"].data)
var EmbedClass:Class = ApplicationDomain.currentDomain.getDefinition("assetEmbedClass") as Class;
var instance:* = new EmbedClass();
You can get this and other classes using my google code.
http://andreanaya.googlecode.com/svn/trunk/
Theres also an example of usage of this class.
Thanks and I hope this could be usefull for you guys. Any problem or sugestion please tell me.
Anaya
Tags: as3, lib
Posted in as3 | 2 Comments »
March 24th, 2009
Early experiments of nothing that could become something.
Use the arrows to control the plane
Speed up pressing space
Demo

Source
Tags: 3d, as3, demo, papervision, source
Posted in as3 | No Comments »
March 23rd, 2009
Last friday I was checking Flash Bookmarks and I noticed a question about Loader.
While ago I needed to load a file using a Loader and then add it to the stage. However it raised an error.
ArgumentError: Error #2025 : The supplied DisplayObject must be a child of the caller.
To solve the problem I needed to extract the conten in a var and then call a loader.unload() before add it to the stage.
function onLoadComplete(e:Event):void{
var image:Bitmap = e.currentTarget.content;
loader.unload();
addChild(image);
}
It’s the same case when you try to load two or more files using the same loader.
Example
Tags: as3, tip
Posted in as3 | No Comments »
March 20th, 2009
I’ve decided to create a google code with my classes, there’s no docs yet but there’s some usage examples
So far there’s 4 libs that I use in my works:
-DataLib
Loader class (example) usign queue
-CromelessPlayer
Video class with playlist
-SoundControl
Sound class (example). *Still need ajustments
-MatrixTween
Tweening class based on Tweener and TweenLite with time control
Tags: as3, repository
Posted in as3 | No Comments »
March 20th, 2009
Tags: work
Posted in works | 1 Comment »
November 24th, 2008
Tags: work
Posted in works | No Comments »
October 10th, 2008
Tags: work
Posted in works | No Comments »
September 16th, 2008
To check if the soundcard is available, test if the SoundChannel class is not null
var sound:Sound = new Sound();
var channel:SoundChannel = sound.play();
if(channel != null){
trace("Soundcard available");
}else{
trace("Soundcard not available");
}
Tags: as3, sound, tip
Posted in as3 | No Comments »
September 3rd, 2008
Here is a method that I use a lot when I need to loop a length of any kind
trace(numberLoop(103754, 3));
//2
trace(numberLoop(686.9384, 17.53));
//3.268399999999957
trace(numberLoop(Math.PI*13/6, Math.PI*2));
//0.5235987755982991 rad - radToDegree == 0.5235987755982991*180/Math.PI -> 30.000000000000014º
trace(numberLoop(-2187.4, 2));
//0.599999999999909
function numberLoop(n:Number, t:Number):Number {
if(t<=0){
throw new Error("Total must be greater thant 0");
}
return (n%t+t)%t;
}
Tags: as3, math, tip
Posted in as3 | No Comments »