""

Archive for January, 2011

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.

Yes i had been reviewing my Actionscript 3.0 code for hour and could not find any reason why my sound_complete event was not getting fired and when you see that logically your code should work fine and u don’t find any logical errors in your code but code doesn’t run as you expected then it pisses me off. 😀
In my code i am playing zombie sound on background when zombies appears and i am replaying sound whenever sound complete playing. So bottom line, i am adding SOUND_COMPLETE event to soundchannel but event doesn’t get fired. Here is the extract from the code that i wrote before my problem got solved:

initSound(){
     zombieSound = new Sound("zombie.mp3");
     soundChannel.addEventListener(Event.SOUND_COMPLETE, zombieSoundComplete);
}

whenZombieEnters(){
soundChannel=zombieSound.play();
}

private function zombieSoundComplete(event:Event):void{
        //replay my zombie sound
}

So that was it and i could not figured out why event wasn’t getting fired. So after googling on this topic i found that whenever i call sound object to play then it returns new instance of SoundChannel so now my soundChannel reference is holding the reference to new returned SoundChannel instance from my zombieSound.play(). SO then i just added the SOUND_COMPLETE event after sound object is called to play. Here is the new code:

initSound(){
     zombieSound = new Sound("zombie.mp3");
}

whenZombieEnters(){
soundChannel=zombieSound.play();
soundChannel.addEventListener(Event.SOUND_COMPLETE, zombieSoundComplete);
}

So the solution, since sound.play() was returning new instance of SoundChannel everytime so i had to add event listener to new instance of Sound Channel so i am adding event after play() call and that solved the problem. Now my SOUND_COMPLETE event is getting fired. Yeppe 😀

Gracias.