""

Tag Archive: Movie Clip

Yeah again i faced a little strange problem that i solved it. In my one of previous post i wrote about using movieclip with plane primitives of papervision and also accessing that movie. Now comes the main discussion of this post that is accessing movieclip from papervision plane.

Lets say i have attached a mouse listener to plane to which moviematerial is mapped. So when i click plane i want to do/manipulate the movieclip that is mapped to plane via moviematerial so code would look something like this:

private function planePressed(event:InteractiveScene3DEvent):void{
var moviemc=event.target.material.movie as Movieclip;
// do manipulation or changes on moviemc
}

the above snippet works, i mean u can access the movieclip on above do the later changes to it if u want.

But lets say there is no listener attached to the plane but later in program cycle i want to modify the movieclip attached to plane like applying blurr filter to it. Then i would do something like this:

var mc=my_papervision_plane.material.movie as Movieclip;
//apply blurr filter to mc

Well the above code didn’t work for me. In previous above event handler i traced event.target and it traced plane object, so it seems like ‘.material’ returned MaterialObject3D so i have to first downcast it to MovieMaterial separately and then try to access movie property on it. Here is the error:

So here is how is the stupid solution 😀

var mat=my_papervision_plane.material as MovieMaterial;
if(mat){//just being safe
var mc=mat.movie as Movieclip;
}

So that worked. But still i didn’t had to do that inside my event handler when i was accessing via even.target, maybe i am missing something out. Right now i am going through docs of papervision.

Gracias

Busy Busy with stacks of projects on hand. I am learning lotsa things while working on them. I love learning new stuffs and programming is my passion. So one project i am working on is flash web page. So i thought to make a 3D flash site with some cool effects. I chose papervision 3D for my project. I am happy with the outcome till now.

But anyway i am here to share some small problems that i face during the development and how i solved it. There must be newbies like me out there who might face this problem :D. So here i’l share how i faced a problem regarding playing movieclip animation mapped to 3d object on papervision 3d.
I had never used movieclip on my previous papervision projects, rather i used bitmaps for graphics. In my current 3d flash site project i was required to use some movieclips also. I opened the papervision documentation and found something called MovieMaterial for creating a texture from my movieclip instance in fla file. Using MovieMaterial is simillar to using ColorMaterial and BitmapFileMaterial. Here i will just be talking about MovieMaterial.
MovieMaterial creates a texture from movieclip to be mapped to 3d object like cube. So i created a MovieMaterial :

materialFront = new MovieMaterial(movieclip_instance1);
materialFront.smooth = true;

movieclip_instance1 is a instance of movieclip in fla library. So i am getting material/texture from the moviclip. So i created other materials for other faces of cube. Then i added all materials to the MaterialList:

cubeMaterials:MaterialsList = new MaterialsList();
cubeMaterials.addMaterial (materialFront, "front" );
cubeMaterials.addMaterial (materialBack, "back" );
cubeMaterials.addMaterial(materialTop , "top" );
cubeMaterials.addMaterial materialBottom, "bottom" );
cubeMaterials.addMaterial(materialLeft, "left" );
cubeMaterials.addMaterial(materialRight, "right" );

Now i just used this matriallist to the cube:

cuboid = new Cube(cubeMaterials, 750, 5, 500, 10, 10, 10);

So movieclip is mapped to all the faces of cube. So this is done. But those movieclips that i mapped were just a single graphics, it didn’t have frame animations inside movieclip. So i mapped a movieclip having animation into it to cube using same above steps and codes but viola, movieclip animation wasn’t playing, just first frame was getting rendered at the face of cube. So this was quite a problem for me because i wanted to render movieclip animation for giving nice effects.

I just googled on this topic and found the solution. I went to papervision documenation again and opened the MovieMaterial doc and looked at the constructor parameters. The last parameter in the MovieMaterial constructor specifies the additional properties associated with the movieclip. Default value is false. So i modified a line of code:

materialFront = new MovieMaterial(movieclip_instance1, true, true);

The second parameter specifies whether movieclip is transparent . Last parameter is what i needed to solve my problem, I passed it true saying i have animation into my movieclip and i want it to play when rendered. So viola movieclip animation was playing and i had a stupid grin on my face 😀

Gracias.

Well i would start by saying that Box2D Flash made my life so easy 😀 and Physics Is FUN 🙂

I have been making physics based 2D platform games in Flash ActionScript 3.0 for just one past one month. yes i am newbie in Flash world. For Physics based game i chose Box2D Flash 2.1 and why did i chose Box2D Flash ?? cuz it had a good reviews from other developers and it was the first library that i stumble into via google haha 😀
But at the end it gets my job done much easier that i thought. Its very powerful library and meets my needs till now.

So i was playing around with the library by going through many tutorials, you’l get many on the net. Many of them were very very useful to me and got me started at instant.

Well now lets come back to the subject of this post: Using Movieclip with Box2D !! Please don’t get confused with the name of the post 🙂 This post is about how i used movieclip from fla library or images with Box2D flash, at start i used to play with shapes like polygons and circles, collision between shapes and all that. But when i learned those things and wanted to make basic game simulation demo then i didn’t know how to use real Images with the library. I searched many tutorials but i didn’t get the way to use real images with the library. Then i stumbled into a forum where this topic has been discussed. So now here i am goint to tell how to use movieclip with library i.e instead of showing circle and polygons moving around and interacting, you’l be using movieclips ot bitmaps.

I’l assume that u know basic setup and use of Box2D Flash 2.1 because i won’t be explaining those things, i’l just explain how movieclip will be used. And maybe someone have better way to use it so please share it in comment.

First of all, for newbies like me, please go to this tutorial. It has good explanation of using Box2D and its concept. The Movielclip from fla that i am using here has been downloaded from here Adobe Article

1) Create the Shape definition for MovieClip that will be used (literally), its shape definition for the box2d shape.

var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.type=b2Body.b2_dynamicBody;
bodyDef.position.Set(SWF_HALF_WIDTH/PIXELS_TO_METER-1.5,4);

2) Create the body. And we are assigning the instance of Movieclip to body using SetUserData function. you could say we are associating Movieclip data to body. I don’t have other way to explain it. 🙂 here texture is the instance of my movieclip that i created in fla file. Image is shown below

Moviclip from fla

var body:b2Body=world.CreateBody(bodyDef);
body.SetUserData(texture);

3) Now we create our shape.

var dynamicBox:b2PolygonShape=new b2PolygonShape();
dynamicBox.SetAsBox(2.1,2.1);

4) We can set various properties when we create the fixture.

var fixtureDef:b2FixtureDef=new b2FixtureDef();
fixtureDef.shape=dynamicBox;
fixtureDef.density=1;
fixtureDef.friction=1.0;
body.CreateFixture(fixtureDef);

5) Set the position of movieclip relative to the position of shape body that movieclip will represent

body.GetUserData().x = body.GetPosition().x*PIXELS_TO_METER;
body.GetUserData().y = body.GetPosition().y*PIXELS_TO_METER;

6) Add the moviclip

addChild(body.GetUserData());

7) I am calling update function on ENTER_FRAME

addEventListener(Event.ENTER_FRAME,update);

8] update function where physics world will update and object will interact

private function update(event:Event):void{
    var timeStep:Number=1/30;
    var velocityIterations:int=6;
    var positionIterations:int=2;

world.Step(timeStep,velocityIterations,positionIterations);

world.ClearForces();

for(var worldbody:b2Body = world.GetBodyList(); worldbody; worldbody = worldbody.GetNext()){

if(worldbody.GetUserData()!=null){

             worldbody.GetUserData().x = worldbody.GetPosition().x*PIXELS_TO_METER;
             worldbody.GetUserData().y = worldbody.GetPosition().y*PIXELS_TO_METER;
             worldbody.GetUserData().rotation=(worldbody.GetAngle())*180/Math.PI;

In above update function, inside for loop, i am iterating through world list for bodies and in each iteration i am checking if each body in world has movieclip/userdata associated. If userdata is not null then i am updating movieclip in this case so we are setting the position values of body shape to our movieclip in general and it will behave as shapes do. I hope i haven’t made u confused . I tried my best to explain this. It works.
Download Source Files

Gracias