Archive for the ‘Code’ Category

Global Mouse_Down Event

Saturday, March 29th, 2008

A time ago I had I little problem, I was doing an application and it had some severed changes, at some point I hasn’t capable of detect some mouse down events because I had a lot of sprites inside of sprites inside of movieClips with lots of event listeners and so on. So I and Hugo found this solution. Basically you put a generic mouse down event on stage and pass an array of objects with the name of the display object you want to catch the event and the name of the function you want to call. One good thing is that you can catch more than one event at the same time even if the displayObjects are in front of another displayObjects.

Note: this is really bad programming, if you can don’t use it, use only in severe cases.

globalmousedown.swf

globalmousedown.zip

hitTestObjects

Friday, March 28th, 2008

This function can be used to test a hit between a displayObject with an amount of displaysObjects (Array). It will return the displayObject where the biggest contact area occurred. Note: it uses the bounding boxes.

hittestobjects.swf

hittestobjects.zip

Get the name of all Xml nodes and Attributes

Thursday, March 13th, 2008

How many times do we have an XML that comes from a webservice or from a source 
that we don't know. In these times getting that xml to a file can be cumbersome (imagine that you have authentication). So how about a nice little way to see all the node and attribute names in that xml, here's how:

Take this xml as an example:
file

For this file we'd get something like:
NODE NAME: Mouse
NODE NAME: ScreenSaver
ATTRIBUTE OF ScreenSaver NAME: desc
NODE CHILD OF ScreenSaver NAME: Active
ATTRIBUTE OF Active NAME: desc
NODE CHILD OF ScreenSaver NAME: File
ATTRIBUTE OF File NAME: desc
NODE CHILD OF ScreenSaver NAME: Time
ATTRIBUTE OF Time NAME: desc
ATTRIBUTE OF Time NAME: min
ATTRIBUTE OF Time NAME: max
ATTRIBUTE OF Time NAME: unit

Hope this helps you out.

Image Sequencer

Thursday, March 6th, 2008

To solve the problem of the image sequence I already know the solution, some time ago me and Pedro did something like this. This time I made two different versions, a class version (project in flex 3) and a component to flash cs3. With this solution, you can keep your images outside the project and manipulate them like a movieClip.

Arguments and Parameters

folder -> images folder.
filename -> first part of filename (ex: image1.jpg ), it should be "image".
type -> extension of the filename (jpg,png).
startImageNum-> first image number.
endImageNum->last Image numer.

For the class (ImageSequencer.as) version use:

For the component version:
Run “ImageSequencer.xmp” to install component. Run flash cs3, go to Windows > Components > Standard Components, drag ImageSequencer to the stage and fill the Parameters.

Methods,Events,Properties:

Flash Component and Example
Class File and Example

HLS to RGB & RGB to HLS

Monday, November 19th, 2007

HLS color scheme can be awful to work with bitmapData, today we discover that motion tracking mechanisms can be improved using HLS, so there's a class for converting RBG to HLS and vice-versa.


ColorUtils.as

Actionscript 3 Preloader

Tuesday, November 13th, 2007

Hey,

So recently i've come to a problem, how do i create a preloader for my 
website if i only use Eclipse as development enviornment?
There is no main timeline per se, nor can i choose where to export my assets, 
so after some digging i came up with  this solution:

The main file:

And the preloader file:

Essentially what i'm doing here is instructing the compiler to add a frame
with myPreloader as a factory and calling my main file from it.
Should you have any questions feel free to ask, here is the swf.

Filling MovieClips with patterns

Monday, November 5th, 2007

Tinting a MovieClip is not a new thing, we see a lot of Web sites doing that, example: In a t-shirt selling store, you choose a shirt and then you can choose it color. But yesterday me and Pedro were talking that it could be nice to fill shapes with patterns, so it quite simple:

Example

Double-faced Plane (or Cube with depth=1) in Papervision3D

Thursday, October 11th, 2007

Today I had my first experiments with Papervision3D and after some time playing around I wanted to try having a double-faced Plane() with a different material on each face.

Its likely that a better way to do this exists, but one way to emulate a double-faced Plane() is to have a Cube with depth = 1, and hiding all but the front and back faces. Here's a and the code.

The hint to do this was from ldoru and the car in the images too!

 Update:  I would not longer use such an approach to achieve a double-faced Plane() with a different material on each face. I would recommend using a DisplayObject3D with two normal one-face planes inside it.

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.