“Be inspired, enjoy your work, keep learning and never forget to play.” — gskinner

currentlabel and currentlabels

Posted: September 26th, 2007 | Author: Ivan Valadares | Filed under: Actionscript3, Code, Tutorial | No Comments »

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

Posted: September 24th, 2007 | Author: Tiago Bilou | Filed under: Actionscript3, Code, Tutorial | 6 Comments »

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

Posted: September 20th, 2007 | Author: Ivan Valadares | Filed under: Actionscript3, Code | 5 Comments »

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

Posted: September 14th, 2007 | Author: Tiago Bilou | Filed under: Actionscript3, Code, Tutorial | No Comments »

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 


Underlined link style in Flash

Posted: September 4th, 2007 | Author: tufao | Filed under: Actionscript2 | 9 Comments »

You want to have that tipical html effect when rolling over a text link showing text underlined? That is one of thouse things that is hard to understand how Marcromedia/Adobe didn't support this from the very beginning.

Sure you can have your text field as html and have your content defined by code with html tags and all, but do you really want to go through all that trouble. Shouldn't that be more simple just using static text?

I came up to a quite simple solution:

Basically styleSheet is created with the underline style which is applied for every object on a MovieClip. Check it out (AS2):

That's it! The underline effect on a link roll over is active for every static or dynamic text field on stage.