Archive for the ‘Code’ Category

currentlabel and currentlabels

Wednesday, September 26th, 2007

currentLabel and currentLabels were a great improvement in flash. About 1 year ago I had a project with lots of characters animations, and as you know sometimes working with designers is not easy. The problem was that I had to run functions when the characters where doing some actions and some of those actions were not controlled by me, there were just embedded in the timeline. If all the animations where equal, like jump in frame 10 I could use the currentframe propriety, but they were not. That work was a really mess, but now with the help of those properties is easy.

On the next example:
Using currentLabels propriety we associated labels to functions, so when the playhead passes throw some label, the respective function is called.
We use currentLabel like a state variable that tells what is the current action of the animation.
The movieClip:
currentlabel.jpg
The code:

Reading Zip files with Actionscript 3

Monday, September 24th, 2007

Last week, while developing an actionscript application, we had the need to read files stored inside a zip file. Our first approach was to use Zinc to deflate the zip file into a temporary directory.

Because some problems arouse with ZINC I took sometime to read about this AS3 Zip Library As it turns out it does a great job and reading and building zip files and it's really easy to use. Make sure you download and install the Library.

After playing around with this Library for a while I wanted to display some images I had inside the zip file. The issue was how to convert a ByteArry into a BitmapData. It took me a while to figure it out , but as it turns out it's really easy.

addFrameScript with parameters

Thursday, September 20th, 2007

There is a little __undocumented__ function that can be very useful sometimes called addFrameScript. It allows you to specify a function that is called when the playhead of the Movieclip timeline enters the specified frame number. This can be a great improvement if you don’t want to write code directly on the timeline or if you don’t want to add an EnterFrame listener to the movieClip.

MovieClip.addFrameScript(frame_number:uint,function_to_call:Function)

Example:

Note: The frame number are zero based (0 to totalframes-1)

This function works well, but it’s impossible to pass arguments to the caller function. After a little research we found Ian Thomas delegate class.

Using delegate class is possible to call a function with arguments in situations that normally you couldn’t. So for addFrameScript we did:

Instantiate classes by name

Friday, September 14th, 2007

A couple of months ago I wanted to instantiate classes based on their name at runtime, using Flex Builder. At the time I read about the method getDefinitionByName. Everytime I tried to use it I got the error

Error #1009: Cannot access a property or method of a null object reference.   

I googled about it and found Daniel R. post on the subject. According to him

"The problem seems to be that if the runtime module makes a side-effect reference to a component, which is not included in the main application, it never really gets included in the SWF and as such causes problems when accessed"   

And his solution was to declare a static instance of the class you wanted to instantiate at runtime.

private static const classInstance:ClassToInstantiate = null;   

This *fix* becomes a problem when you have many classes to instantiate and have to declare an instante for each one. If the classes you want to instantiate are in the flash library (movieclips), there is a workaround for the problem described above.

  • When you export the Flash library, remember to check the "Export SWC".
  • Make sure you include the SWC in the Flex Builder.
  • (Here's the Magic) Just use this arguments in the compiler options:

-include-libraries $PATH_TO_SWC/LIBRARYNAME.swc 

Doing VoIP Calls

Wednesday, August 29th, 2007

We needed our Flash application to be capable of executing VoIP calls. I remember Skype had a developer API and after some digging I ended up coding a C# application that receives messages from the Flash app via a socket and controls Skype accordingly via the Skype4COM wrapper.

There was already a C# example available at the Skype4COM page that unveiled much of the works involved. I just added a socket server and a configuration XML file for skype dialnumber I wanted and the port the application opens and the Flash app has to connect to.

The attached C# code shows how the application can attach itself to Skype, receive event notifications and control it via the commands provided by the API.

Requirements (and tested with): Skype 3.5.0.202, Skype4COM, release 1.0.27.1

Skype needs to be installed on the machine. For Skype4COM to work don't forget to register the DLL by issuing: regsrv32 skype4com.dll

Carrousel How-to

Tuesday, July 31st, 2007

Hi there,

First be sure you have either flash cs3 or flex2 installed on your machine, then you'll want to download the Papervision3d engine.

Now we can get started :)
Look in the code for instructions :)

Download Actionscript source file

And that's it, if you have any questions please post them!! :) We'd love to hear from you.
Lo.