Friday, December 3, 2010

Air for iPhone - loading external .swf files

If you are creating apps for iPhone with Air, you might have the need to load external .swf files.
In my case, it was the need to be able to have downloadable content.
I can't really think of another reason why you would want to do this, normally using .swc files is the way to go.

Anyways..

When you want to load an .swf file from an Air for iPhone application, there's some things you need to know.

Your .swf file cannot contain ANY actionscript whatsoever. Symbols in your library must also NOT be exported for Actionscript.

Adobe's documentation states that the scripting will simply be ignored, but that isn't exactly accurate.

If your .swf file contains Actionscript, the entire load will be ignored.
Which means you won't receive an Event.COMPLETE or even an IOErrorEvent.IO_ERROR when you try to load the file.

So, with no symbols exported to actionscript, all you're left with is animation on the timeline.


But I wanted to use it like a kind of library, where you could neatly pack all your graphics and animations and sounds in 1 swf, load it, and use the assets in your main program.

I've created a basic class to help with this.
Download StageLibrary with example project (flashdevelop)

This also works for android, but you have to change the path of the swf file.
Convenient if you create apps for android and iPhone that use the same assets.. if you're only creating android apps, you don't have the .swf scripting barrier that Apple enforces and can use library symbols like you usually do.


To create a swf file that will work with this class, create a .fla file of 1 frame in size.
and place all the symbols you want to use on stage and give them an instance name.

If you want to create a soundclip, make a movieclip, keep frame 1 empty, and place your sound on frame 2, making sure to add enough frames for the duration of the audio. If you don't add the extra frames, you wont be able to detect when the sound stopped playing.

StageLibrary takes care of loading the swf and collecting all instance names and allows you to quickly 'grab' a clip from stage, to use somewhere else in your app. (You can simply addChild() a clip from the library to your own stage/displayobjectcontainers)
I've also added a function to easily play a sound clip, that also has a callback when the sound is finished.

You can't reuse an object though, you aren't creating new objects, you're just moving them from stage to your app.
You can put more than 1 instance of a symbol on stage though, just make sure you give them a unique instance name.

It is also possible to use more than 1 frame in your main movie, but this has the effect of killing all animation of your objects (except for subclips with animations)

Check out the example project. It should be self explanatory, I even commented the code!
If not, post your questions/remarks here and I'll see what I can do :)




Thanks to Renaun Erickson, Seb Lee-Delisle and Joe Chung.

Also check out Renaun's blog entry with another loading example which helped me figure out what was wrong here


And finally, for those of you who like to tinker some more:
I've found that you CAN create multiple copies of an object on stage by changing frames of your main animation.
get a symbol from stage, go to frame2, go to frame 1 again, now you can get that same symbol again, and now you have 2 yaay.
Unfortunately, it screws up the animation in your object, except for subclips. But it could be useful to know ;)

Happy coding!

Friday, October 22, 2010

Raceportal, our 2nd iPhone App

Hey people,

Another quick note to let you know that our 2nd app "Raceportal" has been approved for the appstore and is now available to buy :)

Check it out here : http://itunes.apple.com/app/raceportal/id396109306?mt=8

Tuesday, September 14, 2010

My first Iphone App

Just a quick note to tell you guys that my first Iphone app is now available for free on the itunes appstore.

click here to download

It's a webcomic reader for Dutch webcomic artists (some comics can be in English)

Artists can upload their comics on my website webcomicsnl.omg.bs and get their comics featured in the app :)

Hope you guys (those of you who have iphone/ipad's or ipod touches) enjoy it :)

Monday, August 16, 2010

Definefont error

Changing the look and feel of a game I developed in FlashDevelop, I suddenly got the following error when trying to compile the project in FlashDevelop:

WARNING: end of tag DefineFont3 is @55343, should be @58327
Build halted with errors (swfmill)."


To make a long story short, this was caused by a textfield that didn't embed any characters. Thanks to Philippe for providing the answer.

So, If you get this error (the numbers after the @ will probably be different) check your movieclips for textarea's without embedded characters.

And to make this short story a little longer: (for those of you who are still reading ;)
My problem in finding this was that I used 1 font library, and had all my textarea's set to use that as the font...
But I still had 2 buttons, with the same font, but not using the font library.
So the error occured when I changed the font in the library.
Now the 2 buttons didn't share a font that other textarea's used, and had characters embedded for them.

And due to the fact that it wouldn't compile, I couldn't visually verify all textarea's to be the same at runtime.

Click here to see my thread about it on Flashdevelop.org.

Sunday, July 11, 2010

Lightning strikes!

I bought a Casio Exilim EX FH-100 camera a while ago because it could shoot video at highspeed.

Yesterday we had a pretty heavy thunderstorm here in the Netherlands, and it turns out that you can make some pretty nice video shots of lightning with the highspeed camera function. check it out : http://tinyurl.com/37gccks on youtube.