Dreammonkey
asked on
Papervision3d Scene3D getChildAt method undefined?
I'm working on 3D terrain generator, I'm using papervsion3d 2.0 .
The terrain is built with tiles. The whole terrain is square (4 by 4 tiles)
every tile is a Plane , each Plane is eventually added to the scene;
I now want to trace the Panes in the scene by using the getChildAt method, but this seems to be nonexistent in the Scene3D class. Should I import/extend it? Is there another method for referencing the children in a Scene3d instance?
Your input is highly appreciated !
The terrain is built with tiles. The whole terrain is square (4 by 4 tiles)
every tile is a Plane , each Plane is eventually added to the scene;
I now want to trace the Panes in the scene by using the getChildAt method, but this seems to be nonexistent in the Scene3D class. Should I import/extend it? Is there another method for referencing the children in a Scene3d instance?
Your input is highly appreciated !
var viewport:Viewport3D = new Viewport3D(0, 0, true, true);
addChild(viewport);
var renderer:BasicRenderEngine = new BasicRenderEngine();
var scene:Scene3D = new Scene3D();
var camera:Camera3D = new Camera3D();
camera.zoom = 11;
camera.focus = 50;
var terSize:uint=2;
var kwad:uint=terSize*terSize;
var row:uint=1;
var mam:MovieMaterial;
var cube:Plane;
var tile:earth;
var terArray:Array = new Array();
for (var i:uint=0; i<kwad; i++) {
if (i==terSize*row) {
row++;
}
terArray.push(new earth());
tile = terArray[i];
mam = new MovieMaterial(tile);
mam.interactive = true;
mam.smooth = true;
mam.animated = true;
cube = new Plane(mam);
cube.name = "Tile "+i.toString();
cube.x = (i-(terSize*(row-1)))*200;
cube.y = 200*(row-1);
cube.addEventListener(MouseEvent.MOUSE_OVER, onTileOver);
function onTileOver(e:Event):void {
trace(e.currentTarget.name);
var lookFor:Plane = scene.getChildAt(0);
//1061: Call to a possibly undefined method getChildAt through a reference with static type org.papervision3d.scenes:Scene3D.
}
scene.addChild(cube);
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Another issue, as long is add the 'MouseEvent.MOUSE_OVER' listener to the plane it works fine,
but when I use 'MouseEvent.CLICK it doesn't, any idea why this is?
but when I use 'MouseEvent.CLICK it doesn't, any idea why this is?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You're right about that, I shall make separate class for it.
Thanks for the code it seems much more solid...
No Luck with the MOUSE_UP listener, I already tried that and MOUSE_DOWN
Could it be the plane is to 'low' so it's underneath the mouse (just a wild guess)
The only change I made is to set :
camera.rotationX = -30;
... but removing this line doesn't solve it...
Any more ideas?
If you like I'll post a new thread...
Thanks !
DM
Thanks for the code it seems much more solid...
No Luck with the MOUSE_UP listener, I already tried that and MOUSE_DOWN
Could it be the plane is to 'low' so it's underneath the mouse (just a wild guess)
The only change I made is to set :
camera.rotationX = -30;
... but removing this line doesn't solve it...
Any more ideas?
If you like I'll post a new thread...
Thanks !
DM
ASKER
mmm,... no luck with the class, what am I doing wrong?
I'm importing it in my main movie like this :
import dreammonkey.MySceneObject3 D;
PS: how could one throw an exception ?
I'm rather new to this sort of thing...
I'm importing it in my main movie like this :
import dreammonkey.MySceneObject3
PS: how could one throw an exception ?
I'm rather new to this sort of thing...
package {
import org.papervision3d.core.proto.SceneObject3D;
class MySceneObject3D extends SceneObject3D {
public function getChildAt( index:Number ):DisplayObject3D {
if (index>this.objects.length) {
return null;
}// or maybe throw an exception?
return this.objects[index];
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Strange :
line 9 :
super(container);
throws this error :
1137: Incorrect number of arguments. Expected no more than 0.
What does super actually do?
line 9 :
super(container);
throws this error :
1137: Incorrect number of arguments. Expected no more than 0.
What does super actually do?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice Work !
If you're up for more (I'm far from home on this one) :
https://www.experts-exchange.com/questions/24123883/papervision3d-unable-to-use-MouseEvents-CLICK-MOUSE-DOWN-MOUSE-UP.html
If you're up for more (I'm far from home on this one) :
https://www.experts-exchange.com/questions/24123883/papervision3d-unable-to-use-MouseEvents-CLICK-MOUSE-DOWN-MOUSE-UP.html
ASKER
small bug, this should be:
if ( index >= this.objects.length)
throw("Invalid index for getChildAt");
if ( index >= this.objects.length)
throw("Invalid index for getChildAt");
ASKER
ok thanks again !
ASKER
I actually need the getChildAt method to work, so I dug into the papervison code and came up with this :
Do you think it's solid?
It seems to be working on my machine...
org.papervision3d.core.pro
I added lines 91 - 104 =>
Open in new window