Accessing stage inside a custom Away3D class.

Software: Away3D 3.x

Pradyumn, Newbie
Posted: 03 October 2012 05:41 AM   Total Posts: 3

We are working on a game in a team. I have to make a class for 3D, so that game developers can use my Away3D functionality, but they don’t have to bother about the 3D world, they’ll simply pass the X and Y positions of an object—

var tile:CustomClass3D_Tile = new CustomClass3D_Tile(400, 300);

and they are expected to do nothing more than this, they are not even supposed to addChild the view, I have to do this is my custom 3D class.

I’m having difficulty in accessing stage of the Main class inside the custom class, so that I can addChild the objects inside the custom class.

   

Avatar
loth, Sr. Member
Posted: 03 October 2012 08:17 AM   Total Posts: 236   [ # 1 ]

hum not clear ?
why you wan’t access stage
in flash you can use Vector3D(x,y,z);
and the “stage” of away3d is the view
view.scene = ...
view.camera = ...

you only have to creat a function to place your object
but i don’t understand the probleme


   

kochumvk, Newbie
Posted: 08 October 2012 05:21 AM   Total Posts: 17   [ # 2 ]

If you are trying to add a 3D object (ObjectContainer3D or mesh) u can add it to your scene var:

private var sphere:Mesh;
private var 
scene = new Scene3D();
scene.addChild(sphere); 

If you are trying to add a 2D object (a sprite or movieclip)

You can access stage using a proxy for stage (I does that way, using pure mvc)

 

   

Avatar
Alex-Crafter, Newbie
Posted: 08 October 2012 07:55 AM   Total Posts: 28   [ # 3 ]

If you use only 1 3dstage, you can easily do this by assigning your scene to a global variable:

//create a global variable outside, like
var s:Object={}

//then use something like this when initiating your scene
var obj:Object={};
   
var 
scene:Scene3D = new Scene3D();
   
var 
camera:Camera3D = new Camera3D();
   
var 
view:View3D = new View3D();
view.antiAlias 4;
view.scene scene;
view.camera camera;
   
 
obj.scene=scene;
 
obj.camera=camera;
 
obj.view=view;

s.core3d=obj;

//you can acess your 3d scene, view and camera quickly with
s.core3d.scene
s
.core3d.camera
s
.core3d.view 

But maybe this is too procedural programming for your likes..

 

   

Avatar
Darcey, Moderator
Posted: 08 October 2012 12:51 PM   Total Posts: 209   [ # 4 ]

In the AFTC article Away3D 4 VideoMaterial @:
http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=4&subindex=3&aid=332

Demo and source is all there…

I have used what I call my standard application structure.

1. Application entry class.
2. Defines stage in Variables.stage (via public static var stage;) so it becomes a singleton and can be called any time you need it. But I only put it there for quick fix purposes when stage has been lost.

But my typical flow would be:
1. Entry class extends sprite
2. Application class extends sprite (The spine of the application)
3. Away3DScene class extends sprite

In each only assemble when added to stage listener is fired thus ensuring you have access to the stage in each of the classes. EG:

Application.as

class Application {
   
private var away3DScene:Away3DScene;

   public function 
Application()
   
{
      this
.addEventListener(Event.ADDED_TO_STAGE,init);
   
}

   
public function init():void
   {
      this
.removeEventListener(Event.ADDED_TO_STAGE,init);

      
away3DScene Away3DScene.getInstance(); // Singleton pattern
      
addChild(away3DScene); // As this class has access to the stage so will this one ensuring it has been added to the stage

      // Build a mesh code

      
away3DScene.scene.addChild(MyMesh);


Also Instantiating Away3D as a singleton view allows you to call the view from anywhere at any time via:

var away3DScene:Away3DScene;
away3DScene Away3DScene.getInstance(); 

So even access to the stage is not really necessary.

But if you did need it, and you defined it as a static variable in Variables.as you would be able to simply use.

Variables.stage.stageWidth//etc Just make sure it's defined 

Anywere in your application with no problems.


But there are many ways….

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X