Archive for the ‘WorkAround’ Category

The MXMLLoader Class > Dynamic load MXML In Flex Builder 3

Thursday, April 24th, 2008

First of all I don’t really use flex to do flex stuff and I’m not a big fan of flex. But in my latest project I had to build with flex an interface witch would be always diferent (a dynamic interface). In the beginning we thought in parsing some type of XML, but if we are in flex why not parse MXML? I took a look over the internet and I only found MXMLLoader component v0.01, witch didn’t compile on flex builder 3 and was really in the beginning. So there it is, as XMMLLoader class for flex builder 3. You just have to instantiate the class with the mxml :

You can access objects by name:

Or by id:

And have access to component events like:

The class with an example:

mxml-loader.zip

Example swf

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

Papervision3d GW Memory Leak

Tuesday, February 19th, 2008

Yesterday I came across a nasty leak with GW, it just wouldn't kill my moviematerials after I removed all the references to them, I tried it all, removeChild, removeListener, weak keys... you name it.

So I finally decided to go have a look at Papervision's destroy methods, and surprise surprise they weren't being called, no harm there, it's alpha these things are meant to happen :)

So here's what you have to do to force those destroy methods to execute, and clean your memory.

In org.papervision3d.core.proto.MaterialObject3D  set the destroy method from protected to public, do the same to all the materials that you use, like org.papervision3d.materials.MovieMaterial . When you're done with these just the destroy method in your class. For me it looks something like this:

Hope this helps.

Customized actions for FLVPlayback Component

Tuesday, January 22nd, 2008

If you need a standard flash videoplayer, then the FLVPlayback component is the right thing for you.

Just create a new FLA and drag&drop a FVLPlayback component from the components library into a movieclip in your library, export it for actionscript and compile the SWC.

All the functionallity stuff is already handled by adobe. But that's where I got stuck for quite some
time. I needed a player, that used the forwardButton and backButton for switching the videos (and not seeking forward and back).

The answer was really simple: Just override the functions once the component loaded its skin:



Taking a snapshot of an flv

Monday, December 3rd, 2007

Following my last post on 9-Slice items, here comes another nice one on Bitmap.draw() and the security sandbox.
Many people know the solution to this one, but i just found myself looking for it for too long, so here it goes :)

If you want to take a snapshot of a running Video object, you can't, you'll be alerted by the flash player that you are violating
the sandbox security. So how do we do it?
Easy as pie :)

video.attachNetStream( null );
bitmapData.draw( video );
video.attachNetStream ( myNetStreamObject );

Three very simple lines of code but that are hard to come by.

9-Slice and Bitmap

Monday, December 3rd, 2007

Have you ever tried to take a snapshot using bitmap.draw() of a movieclip that has 9-slice enabled?

//my9SliceEnabledMc is a 40 by 40 9-slice enabled movieclip on stage
my9SliceEnabledMc.width = 200;
my9SliceEnabledMc.height = 300;
var myBitmapData = new BitmapData(200,300);
myBitmapData.draw(my9SliceEnabledMc);
addChild(new Bitmap(myBitmapData));

So what you'd expect to happen above is to have a new bitmap that looks the same as my9SliceEnabledMc,
but what you get instead is the original 40x40 movieclip.
This doesn't make sense at all, i have no idea what Adobe was thinking when they let this one through.
This was driving me crazy for a while now, and today i finally found the answer, as simple as it seems,
putting the my9SliceEnabledMc inside another sprite corrects the issue!!

//my9SliceEnabledMc is a 40 by 40 9-slice enabled movieclip on the library
var myContainer = new Sprite();
var my9SliceEnabledMc = new my9SliceEnabledMc();
myContainer.addChild(my9SliceEnabledMc);
my9SliceEnabledMc.width = 200;
my9SliceEnabledMc.height = 300;
var myBitmapData = new BitmapData(200,300);
myBitmapData.draw(myContainer);
addChild(new Bitmap(myBitmapData))

Also i should add that this is a major issue with PV3D since you cannot directly use a 9-slice item as a texture.