Reyco1’s Flash Blog Just another flash blog… Or is it?

"Ive been burned too many times!" I mean, what can I say... I've been working with Flash since it was called Future Splash and as much as you get to know, you never know it in its entireity. With that in mind, here you will find all the solutions I've been able to implement through the past years along with experiments, classes and other stuff!

Blog facelift

Reynaldo May 26th, 2008

Hi All:

Decided to give the blog a new look considering I saw the same template a few times in one day on other blogs :)

After a few hours of searching, I finally decided on this one. I hope its not too crappy! :)

Box3D Class for Papervision3D

Reynaldo May 20th, 2008

Hi All!

Today I found myself with the need to create a cube, but in my case, I wanted to have all the sides of the cube treated as if they were planes. Also, I wanted to have more control over the inner workings of my cube hence the birth of the Box3D class.
All this class does is create a cube out of 6 planes primitives. It works very much like the EnhancedPlane class mentioned in an earlier post .

This is the result:

This movie requires Flash Player 9

You can get the source and example files here!

Tags: , , , , , ,

EnhancedPlane: interactivity simplified

Reynaldo May 18th, 2008

Hi all:

I’ve received a few requests in order to make interactivity on the EnhancedPlane class a bit more simple and straight forward, [EDIT: link updated] so here it is ;) . In order to get it working, you would have to import the InteractiveScene3DEvent event class:

import org.papervision3d.events.InteractiveScene3DEvent;

Now, set up your EnhancedPlane as so

[source language='Ruby']
var frontMaterial:MovieAssetMaterial = new MovieAssetMaterial(”front”, true);
var backMaterial:MovieAssetMaterial = new MovieAssetMaterial(”back”, true);

var materials:MaterialsList = new MaterialsList({
ront: frontMaterial,
back: backMaterial
});

doublePlane = new EnhancedPlane(materials, 250, 250, 16);
doublePlane.interactive = true;
doublePlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, rotatePlane);

view.scene.addChild(doublePlane);
[/source]

As you can see, the EnhancedPlane class now has an interactive property which accepts a Boolean value, then simply listen to an InteractiveScene3DEvent and your set!

[EDIT] To access each side of the plane individually, all you have to do is

[source language='Ruby']

doublePlane.front

[/source]

[source language='Ruby']

doublePlane.back

[/source]

EnhacedPlane and PlaneGrid PV3D classes

Reynaldo May 4th, 2008

Hi!

It’s been a really long time since I posted anything and there are a ton of reasons for that including moving to New York, getting a new job and finding a new place. But you can trust that I will be posting on a more regular basis from now on ;)

I decided to come back with a couple of classes I cerated for use with the Great White branch of PaperVision3D.

EnhancedPlane
This class allows you to create a Plane primitive with two dynamic faces to which you can add different materials. In other words, it’ll have two unique sides!

Use:

var frontMaterial:ColorMaterial = new ColorMaterial(0x00FFFF);
var backMaterial:ColorMaterial = new ColorMaterial(0xFFFF00);

var materials:MaterialsList = new MaterialsList({front:frontMaterial,	back:backMaterial});

var myEnhancedPlane:EnhancedPlane = new EnhancedPlane(materials, 250, 250, 16);
this.scene.addChild(myEnhancedPlane);

The first argument the class accepts is a MaterialList with the “front” and “back” materials specified. After that, the class accepts 4 optional arguments: width, height, segments and name.

PlaneGrid
This class allows you to create a grid of (same width, same height) planes real easily!

Use:

var planesArray:Array = new Array();
for(var a:Number = 0; a<18; a++){
     var material:ColorMaterial = new ColorMaterial(0x00FFFF);
     var plane:Plane = new Plane(material, 320, 480);
     planesArray.push(plane);
}
var planeGrid:PlaneGrid = new PlaneGrid(planesArray, 6, 3, 5, 320, 480, "left");
this.scene.addChild(planeGrid);

The first argument is an array holding the planes you would like to be in the grid, the rest of the parameters are columns, rows, spacing, plane width, plane height, and alignment respectfully. The alignment can either be: “left”, “right” or “center”.

Both of the classes extend the DisplayObject3D so you can treat them like any other 3D display object/primitive.

You can get the classes here

[EDIT]

Thanks to my good friend Matt, I fixed a small error in the the EnhancedPlane class. Thanks dude! I also uploaded an example on how to set up your EnhancedPlane to have interactivity on both sides. You can find the example here.

Event Control System

Reynaldo February 26th, 2008

When working on large scale projects or even small projects, I try to be as organized as possible. That’s why I love to use patterns such as the Command pattern or the Model View Controller pattern, organization. Every class has their job to do. Some classes have no idea whats going on outside of them and do only as they’re told while other classes take the role of a “Command Center of Operations” listening to events and delegating tasks to sub classes or”minion” classes.

One thing that I strive to always keep on point is communication between classes via events. It’s really not any fun when you have a rogue event being fired from somewhere; it then being handled and you have no idea who’s doing what :( that’s where an “Event Control System” comes in really handy!

An Event Control System is composed basically of a pair of classes which handle all the global, project specific firing of and listening of events.

The first class I tend to call “EventCentral.as”. The EventCentral is a Singleton class which extends flash.events.EventDispatcher and is used across the project classes to dispatch and listen to project events. The project events are basically all public static constants in the second class called “ProjectEvent.as”. The ProjectEvent extends flash.events.Events.

The good thing about extending the Events class, or any class for that matter, is that you can add additional functionality. In the case of the ProjectEvent class, we add a “params” object which the custom event which is fired can carry or piggyback. Any event handler can then pull this “params” object from the event being listened to. This is an example as to how the classes would be used:

First import the class:

import EventCentral;
import ProjectEvent;

To dispatch an event, it would look like this:

EventCentral.getInstance().dispatcheEvent(new ProjectEvent(ProjectEvent.SOME_EVENT, {name:"Reynaldo"}));

To listen to and handle the event:

EventCentral.getinstance().addEventListener(ProjectEvent.SOME_EVENT, someEventhandler);
function someEventhandler($event:ProjectEvent):void
{
    trace($event.params.name)
}

Thats it! Just remember not to have a slew of events handling absolutely everything in your projects, I’ve had bad experiences when abusing this method. But enough chit chat, you can find the two classes with an example here:

CentralEventSystem.zip

« Prev - Next »

  • Friends

  • Props

  • Donations

  • website counter
  • Archives

  • Feedburner

  • Saavn