Showing posts with label Actionscript 3. Show all posts
Showing posts with label Actionscript 3. Show all posts

Saturday, May 17, 2008

ProxyLoader Class

With my latest project I had lots of external assets loading. I wanted to make sure people knew something was happening while an asset was loading and I didn't want to create a preloader everytime, in comes ProxyLoader.
ProxyLoader is simply a Sprite that takes care of loading the asset via a Loader, draws a preloader, and border. It then destroys the preloader after the asset has been loaded.
One feature I added to this Class is the ability to create any type of visual preloader using the IPreloadable interface. So you can have a text preloader of one type of asset and a Movieclip for another as long as it implements the interface.
You can use the class in a very similar fashion as Loader, but you need to pass a width and height argument.

var loader:ProxyLoader = new ProxyLoader(435, 250);
loader.load(new URLRequest("path.to.asset"));
addChild(loader);

If you want to see the methods I have posted some docs here. You can download the package here. Hope it helps someone out.

Tuesday, February 12, 2008

Reading a local database created with AIR

I found this neat little app that reads a SQLite database, so you can quickly and easily see whats been written to the database from your AIR file.

Hopefully, it will help you as much as it's helped me recently ;)

Wednesday, February 6, 2008

AS3 Custom Events

I've read in couple of blogs (this one recently) on the problems with passing data between Objects/Classes. I, myself, used to use Proxy as well as binding data to dynamic classes (ie-MovieClip) a LOT of the time in AS2, but now in AS3 things have changed (for the BETTER!).
In comes Custom Events. I recently used Custom Events in a project where I wrote a Class for controlling the Sound object. I found using Custom Events was MUCH easier than it's reputation is known for, and very similar in nature to Proxy. Below is a quick Sample of the SoundControlEvent.





With CustomEvents it easy to read the passed property without having to access the dispatching object. As outlined below:

var evt:SoundControlEvent = new SoundControlEvent(SoundControlEvent.SOUND_POSITION);
evt.position = _channel.position;
dispatchEvent(evt);

Hopefully Custom Events will become more popular as AS3 gets futher into the mainstream. It makes for easy to read code that extremely portable.

Monday, February 4, 2008

Communicating between AIR (swf) windows

I wanted to make a quick note on something I came across yesterday as I was working on my AIR app that uses separate NativeWindows.
Essentially what I wanted to do was call a method in another swf and pass it an argument.. a path to a song in the local file system. The way I approached this was with LocalConnection. (If there is another way to communicate between NativeWindows please let me know!) I had set up listeners in the swf for a status.level of either 'status' or 'error' so I could make sure I was actually communicating. Every time I tried to communicate between the two swf's I would get an 'error' condition. What was the problem? It seems that in AIR you must allow the local domain. As soon as I added:

_conn.allowDomain('*');
Everything worked fine.

Hopefully this will help someone searching for some answers on communicating between windows.

Sunday, February 3, 2008

Multiple Windows in AIR

I was working on my MusicPlayer app and I wanted to open my player from the playlist manager in another window. This actually isn't very hard, but if you're not careful you'll open the new window and nothing will appear! That's because after you've initialize all the NativeWindow properties you MUST set the visible property to true. If you don't, the window is created but nothing is visible on screen.

Luckily for me I was opening a swf with sound or else I wouldn't never known something fishy was happening and might've thought I was initializing it incorrectly. I could hear the music but I couldn't see anything. After reviewing some examples, I could see the error of my ways.

On a similar note, make sure you set the stage.scaleMode and stage.align properties for the new window or else you may end up with a very odd sized loaded asset.