Posts Tagged ‘Actionscript3’

This tutorial is an expansion on Loading 3D objects created in Max (using COLLADA)…

There are 3 main methods that can be use in Flash Actionscript to import bitmaps (i.e. textures)
BitmapAssetMaterial doesn’t work because the function expects a linkage id, linkage ids were in as2, not as3. so this will never work (I think).
BitmapFileMaterial Just links to a url file and therfore doesn’t need anything in the library.
BitmapMaterial is the one to use when you have a bitmap in the library. it expects a Bitmapdata object.
so, to get it to work with a material called examplematerial in the library with the class name examplematerial use:
BitmapMaterial(new examplematerial(width, height));
changing the width and height to the dimentions of the examplematerial image.
Also, this is assuming your examplematerial parent class is bitmapData (the default for an image so it should be).
So if you find that for some reason BitmapFileMaterial is not being loaded from your .DAE file, then simply change it and use BitmapMaterial.
To do this firstly in your .FLA file in the toolbar:
File > Import >  Import to Library
select your texture file and choose ok (I would use a .PNG file type, as they keep file sizes small, allow for transparency, and retain original quality)
once your texture is imported into the library make sure you right click it and select Linkage…
this will pop up with a window, make sure you have the relevant boxes ticked and have filled in the Class section with the name of your texture, in this case “examplematerial”
once this is done, go back into you .as file and add the following lines of code:
var myobjMaterials:MaterialsList = new MaterialsList();myobjMaterials.addMaterial(new BitmapMaterial(new sacktexture(1024, 1024)));

and thats all there is to it!

This tutorial will show you how to basically import a 3D object into Flash, using Papervision.
IF you are completely new to this (i.e. need to know how to set up flash and PV3D, then please follow this tutorial steps 1-4 and read the beginners guide to creating your first 3D shapes here – if you want to know how to export 3D files into the COLLADA .DAE format that papervision read steps 2 -3 here.

This tutorial, assumes that you have read the other tutorials linked above, that provide full explanations for beginners!
In order to import a 3D object, you need to convert(export from 3Ds Max – COLLADA max extension can be downloaded here) it into a .DAE (COLLADA) file that papervision can use,  we will then use AS3 to read this file, and import the model.
import org.papervision3d.view.BasicView; 
//For importing objects  
import org.papervision3d.objects.parsers.Collada; 
import org.papervision3d.objects.parsers.DAE; 
import org.papervision3d.objects.DisplayObject3D;

 [SWF(width="640", height="320", backgroundColor="#000000", frameRate="60")]

 public class import3D extends BasicView 
public function import3D()  
var myFirstObject= new Collada("myfirstobject.dae");   
//Set different scales, if your models is too small or too big   
myFirstObject.scaleX = 8;   
myFirstObject.scaleY = 8;   
myFirstObject.scaleZ = 8;   
//rotate object if you want it at a different angle   


And thats all there is to it! – very simple once you know how – keep an eye out for the next tutorial – TEXTURING! :)

subscribe to my RSS feeds, to get the latest updated tutorials!

This tutorial is designed for Flash Actionscript 3.0 with PV3D 2.0 (GreatWhite) repositries..

Before you begin, please make sure that you have downloaded the necessary PV3D repositries
from the SVN. [if you dont know how to this, then please check step 1 AND step 4 in this tutorial]

If you have already done this then please read on!

first off, we will create an empty .FLA file (this will allow us to read the .as file we will make
and will help us run it!)

File > New (ctrl+N)
select Flash File (Actionscript3) and click ok.
Now save that under whatever name you like.

Now we need to create an Actionscript file (.as)
File > new (Ctrl+N)
select Actionscript File and click ok.
Now save this using whatever name you like – I will call it

It is in this file where we will write our code. but first we need to link
it to the .FLA file we made earlier.
click on the tab to open your .FLA file and look near the bottom of your screen, in the
properties tab, for something called Document Class in the text box to the right of it, enter
your .as file name – in this case example and click on the little pencil icon to scan for the file.

now that the files are linked we can compile and run our actionscript when we need to test
out our video.

now for the code – put this in you .as file:

import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.BasicView;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
//For importing objects
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.objects.DisplayObject3D;

 [SWF(width="640", height="320", backgroundColor="#000000", frameRate="60")]

 public class Example extends BasicView {
//private var myMaterials:Object;

     public function Example()
var sphere:Sphere = new Sphere();
sphere.x = 150;
//text output in debuger window to see if code
//is going through loop
trace("DRAW sphere");

var plane:Plane = new Plane();
plane.x = -150;
trace("DRAW plane");

var cylinder:Cylinder = new Cylinder();
trace("DRAW cylinder");


Now to test what we have written, press ctrl+enter key and wait for the results!

For a 3D cube, add the following code, before “startRendering()”

//FOR 3D CUBE   //code for material - more will  be covered on this later
var frontMaterial:WireframeMaterial = new WireframeMaterial();
var backMaterial:WireframeMaterial = new WireframeMaterial();
var leftMaterial:WireframeMaterial = new WireframeMaterial();
var rightMaterial:WireframeMaterial = new WireframeMaterial();
var topMaterial:WireframeMaterial = new WireframeMaterial();
var bottomMaterial:WireframeMaterial = new WireframeMaterial();

var materialsList:MaterialsList = new MaterialsList();

materialsList.addMaterial(frontMaterial, "front");
materialsList.addMaterial(backMaterial, "back");
materialsList.addMaterial(leftMaterial, "left");
materialsList.addMaterial(rightMaterial, "right");
materialsList.addMaterial(topMaterial, "top");
materialsList.addMaterial(bottomMaterial, "bottom");

var cube:Cube = new Cube(materialsList);
//cube.x = 100;
//need to rotate cube, otherwise it will look like a Plane.
cube.rotationY = 45;
cube.rotationX = 45;
//END 3D Cube

A tutorial for loading in 3D objects made in a 3D package such as Max can be found here

subscribe to this blog, and you will be notified as soon as the post is made!

This is soo cool, every PV3D developer should have one!

Follow the link:
UPDATE: A better a more complete tutorial can now be found here:

To Load .DAE files – simply use this code in Flash AS3:

import org.papervision3d.objects.parsers.*;
import org.papervision3d.objects.DisplayObject3D;
private var modelDAE:DAE;
private function load(){modelDAE = new DAE( );modelDAE.texturePath = “”; // assume that textures are in main DAE’s foldermodelDAE.load( “path/to/file.dae” );
modelDAE.addEventListener( FileLoadEvent.LOAD_COMPLETE , ldrComplete );}
private function ldrComplete( e:Event ):void{try{model = DisplayObject3D( modelDAE );
catch( e:TypeError ){loading = ERROR;return;}//And then you simply call the load

There are no error handlers in this code, only the basics of importing a model and loading it in flash. – more detailed tutorials will come soon with user interaction!

sign up to the RSS feed to find out when i have released it!
Follow me on Twitter
free counters
PayPal Donation
If you like this blog and the help it has given you, why not donate for this good cause? Click on the button below to pay Safely and Securely through PayPal.