importing converted model problem (the essential guide to 3d in flash)

Software: Away3D 3.x

faroer, Newbie
Posted: 19 October 2011 03:26 PM   Total Posts: 18

Hello Away3D community,

I’m currently using the book: The Essential Guide to 3D in Flash and I’m stuck at chapter 4.

The problem is I have converted a 3ds model to as3.  But I need to import it into the class. I’m using the script provided with the book. But I’m getting an error. It doesn’t seem to recognise _view

Here is the script I’m using:

package 
{
 import away3d
.core.base.*;
 
import away3d.lights.*;
 
import away3d.materials.*;


 
import flash.display.*;
 
import flash.events.*;
 
import flash.net.*;
 
import flash.utils.*;
 
 
import models.common.PlanetWinter;
 
 public class 
pictor extends MovieClip
 {

  
public function pictor()
  
{
   super
();
  
}
  
  
protected function _createScene()
  
{
   
var material:ShadingColorMaterial = new ShadingColorMaterial(0x888888);
   var 
planetWinter:PlanetWinter = new PlanetWinter();
   
planetWinter.material material;
   
planetWinter.= (Math.random()-0.5) * 512
   planetWinter
.= (Math.random()-0.5) * 512
   planetWinter
.= (Math.random()-0.5) * 512
   
   _view
.scene.addChild(planetWinter);
   
   var 
light:PointLight3D = new PointLight3D();
   
light.500;
   
light.500;
   
light.0;
   
_view.scene.addLight(light);
  
}
  
 }

When I run this code I’m getting the following error:

1120: Access of undefined propery _view.

As the error says it seems that he does not recognise _view which I think is weird because I worked before with other scripts from the book.

And there is nothing about it in the Errata

Does anyone can help me with this?

   

Richard Olsson, Administrator
Posted: 19 October 2011 05:41 PM   Total Posts: 1192   [ # 1 ]

Have you really found this code in the book? Most examples in the book extend a per-chapter base class, but you are extending MovieClip. The code that you are using does not have a _view variable declaration anywhere, which is why it can’t find it. It makes complete sense. The examples in the book work because the _view variable is declared either in the base class or in the example class itself.

   

faroer, Newbie
Posted: 19 October 2011 06:04 PM   Total Posts: 18   [ # 2 ]
Richard Olsson - 19 October 2011 05:41 PM

Have you really found this code in the book? Most examples in the book extend a per-chapter base class, but you are extending MovieClip. The code that you are using does not have a _view variable declaration anywhere, which is why it can’t find it. It makes complete sense. The examples in the book work because the _view variable is declared either in the base class or in the example class itself.

I forgot to extend it as a sample base.

Thanks Richard. I totally forgot about it. I thought Away 3d recognised everything.


Another question. I’ve copied some stuff that I needed from the base class. This is what I have

package 
{
 import away3d
.core.base.*;
 
import away3d.lights.*;
 
import away3d.materials.*;
 
import away3d.cameras.*;
 
import away3d.containers.*;


 
import flash.display.*;
 
import flash.events.*;
 
import flash.net.*;
 
import flash.utils.*;

 
import models.common.PlanetWinter;

 public class 
pictor extends MovieClip
 {
  
protected var _camera:HoverCamera3D;
  protected var 
_view:View3D;

  public function 
pictor()
  
{
   trace
("test0");
   
super();

   
_createScene();
   
_createView();
   
trace("test1");
  
}


  
protected function _createView():void
  {

   _camera 
= new HoverCamera3D();
   
_camera.distance 1000;
   
_camera.tiltAngle 10;
   
_camera.panAngle 180;

   
_view = new View3D();
   
_view.400;
   
_view.300;
   
_view.camera _camera;
   
addChild(_view);
   
addEventListener(Event.ENTER_FRAME_onEnterFrame);
  
}
  
  
protected function _createScene():void
  {
   
var material:ShadingColorMaterial = new ShadingColorMaterial(0x888888);
   var 
planetWinter:PlanetWinter = new PlanetWinter();
   
planetWinter.material material;
   
planetWinter.= (Math.random()-0.5) * 512;
   
planetWinter.= (Math.random()-0.5) * 512;
   
planetWinter.= (Math.random()-0.5) * 512
   
;
   
_view.scene.addChild(planetWinter);
   
trace("test2");

   var 
light:PointLight3D = new PointLight3D();
   
light.500;
   
light.500;
   
light.0;
   
_view.scene.addLight(light);
   
trace("test3");

  
}

  
protected function _onEnterFrame(ev Event):void
  {
   _camera
.panAngle += (stage.mouseX stage.stageWidth/2) / 100;
   
_camera.hover();

   
_view.render();
  
}

 }

But now I get a #1009 error. He does not recognise the function _createScene()  (line 27)

   

faroer, Newbie
Posted: 21 October 2011 02:21 PM   Total Posts: 18   [ # 3 ]

Bump…..

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X