I removed loader class vars and implimented changes as you suggested:
var obj1:Object3DLoader = Obj.load("assetts/teapot_1.obj", ... all is
good there.

I had thought late last night to use the Object3D instead of the
loaders
obj2object3d.visible=false;
obj3object3d.visible=false;
obj1object3d.visible=true;

etc,etc.... tried it, still not work ...

Just changed button handler and added some tracing:

private function txtButMouseDown(event:MouseEvent):void
{
if(objtoload == 3){objtoload=0}
objtoload+=1;
trace("objtoload "+objtoload)
if (objtoload==1){
        trace("objtoload load 1");
        obj2object3d.visible=false;
        obj3object3d.visible=false;
        obj1object3d.visible=true;}
if (objtoload==2){
        trace("objtoload load 2");
        obj3object3d.visible=false;
        obj1object3d.visible=false;
        obj2object3d.visible=true;}
if (objtoload==3){
        trace("objtoload load 3");
        obj2object3d.visible=false;
        obj1object3d.visible=false;
        obj3object3d.visible=true;}

trace("obj1object3d state="+obj1object3d.visible)
trace("obj2object3d state="+obj2object3d.visible)
trace("obj3object3d state="+obj3object3d.visible)
}

trace on button presses give:

"1st press"
objtoload 1
objtoload load 1
obj1object3d state=true
obj2object3d state=true
obj3object3d state=true

"2nd press"
objtoload 2
objtoload load 2
obj1object3d state=true
obj2object3d state=true
obj3object3d state=true

"3rd press"
objtoload 3
objtoload load 3
obj1object3d state=true
obj2object3d state=true
obj3object3d state=true

... all 3 objects are displayed on screen all the time and visibility
state remains TRUE for all ... ugh :S

I really am trying to get this on my own and trying to avoid bothering
people ...

updated project file is here:
http://groups.google.com/group/away3d-dev/web/Test67.zip

Test67.as is here:
http://groups.google.com/group/away3d-dev/web/Test67.as

swf in action is here:
http://www.vespan.com/Test67.swf


On Apr 25, 1:08 pm, Fabrice <[email protected]> wrote:
> Hi Jojo,
> What you need to do is read your own code a bit better :)
> You try to set the visible property to an Object3dLoader, not an  
> Object3D!!
>
> > private var obj1:Object3DLoader;
>
> while you want show/hide an object3D;
> you have declared them:
> obj1object3d = e.loader.handle;
>
> so just:
> obj1object3d.visible=false/true
> in your txtButMouseDown method.
>
> Also you render on enterframe, clear all the render calls from your  
> txtButMouseDown method as well.
>
> Since you do not use the ObjectLoader further in your code,
> just do for the 3 loaders
> var obj1:Object3DLoader = Obj.load("assetts/teapot_1.obj",  
> { material:material } );
> and remove the 3 class vars from your class.
>
> Fabrice
>
> On Apr 25, 2009, at 9:50 PM, jojo wrote:
>
>
>
>
>
> > It does view.render() in the onEnterFrame so I assumed it was ok.
>
> > I went overboard perhaps and put explicit view.render(); statements
> > after each obj.visible change ... still doesn't work
>
> > I really don't see why this should not work ...
>
> > I can certainly appreciate that looking at anothers code is annoying
> > at times but anyhelp is greatly appreciated.
>
> > Here's the code so no one has to take time to unzip ...
> > CS4 demo, away3d v3.3.3, btw
>
> > package
> > {
> > import flash.display.*;
> > import flash.events.*;
> > import fl.controls.Button;
>
> > import away3d.loaders.Obj;
> > import away3d.events.LoaderEvent;
> > import away3d.loaders.Object3DLoader;
> > import away3d.core.base.*;
> > import away3d.core.render.*;
> > import away3d.cameras.*;
> > import away3d.containers.*;
> > import away3d.core.utils.*;
> > import away3d.lights.*;
> > import away3d.materials.*;
> > import away3d.events.MouseEvent3D;
>
> > [SWF(backgroundColor="#888888", frameRate="30", quality="LOW",
> > width="500", height="400")]
>
> > public class Test67 extends Sprite
> > {
> > private var scene:Scene3D;
> > private var camera:HoverCamera3D
> > private var view:View3D;
> > private var light:DirectionalLight3D;
> > private var navigate:Boolean = false;
> > private var lastMouseX:Number;
> > private var lastMouseY:Number;
> > private var lastzoom:Number;
> > private var lastMouseYzoom:Number;
> > private var lastRotationX:Number;
> > private var lastRotationY:Number;
> > private var move:Boolean = false;
> > private var lastPanAngle:Number;
> > private var lastTiltAngle:Number;
> > private var cZoom:Number=6;
> > private var obj1:Object3DLoader;
> > private var obj2:Object3DLoader;
> > private var obj3:Object3DLoader;
> > private var obj1object3d:Object3D;
> > private var obj2object3d:Object3D;
> > private var obj3object3d:Object3D;
> > private var objtoload:Number=0;
> > private var textBut:Button;
>
> > public function Test67()
> > {
> >    init();
> > }
>
> > private function init():void
> > {
> >    initEngine();
> >    initObjects();
> >    initLights();
> >    initUI();
> >    initListeners();
> > }
>
> > private function initEngine():void
> > {
> >    scene = new Scene3D();
> >    camera = new HoverCamera3D({zoom:cZoom, focus:200, distance:1500});
> >    camera.targetpanangle = camera.panangle = -180;
> >    camera.targettiltangle = camera.tiltangle = 15;
> >    camera.yfactor = 0.8;
> >    view = new View3D({scene:scene, camera:camera});
> >    view.x = 300;
> >    view.y = 200;
> >    addChild( view );
> > }
>
> > private function initUI():void
> > {
> >    textBut=new Button();
> >    textBut.label="Change Object";
> >    textBut.toggle=false;
> >    textBut.move(20,10);
> >    addChild(textBut);
> > }
>
> > private function initObjects():void
> > {
> >    var material:BitmapFileMaterial = new BitmapFileMaterial("assetts/
> > teapot_1.jpg");
> >    var material2:BitmapFileMaterial = new BitmapFileMaterial("assetts/
> > teapot_2.jpg");
> >    var material3:BitmapFileMaterial = new BitmapFileMaterial("assetts/
> > teapot_3.jpg");
>
> >    obj1 = Obj.load("assetts/teapot_1.obj", { material:material } );
> >    obj2 = Obj.load("assetts/teapot_2.obj",  {material:material2 } );
> >    obj3 = Obj.load("assetts/teapot_3t.obj",  {material:material3 } );
>
> >    obj1.addOnSuccess(onLoaderSuccess);
> >    obj2.addOnSuccess(onLoaderSuccess);
> >    obj3.addOnSuccess(onLoaderSuccess);
> >    scene.addChild(obj1);
> >    scene.addChild(obj2);
> >    scene.addChild(obj3);
> >    obj1.visible=false;
> >    //obj2.visible=false;
> >    obj3.visible=false;
> > }
>
> > private function onLoaderSuccess(e:LoaderEvent):void
> > {
> >    obj1object3d = e.loader.handle;
> >    obj2object3d = e.loader.handle;
> >    obj3object3d = e.loader.handle;
> >    var mesh1:Mesh = (obj1object3d as ObjectContainer3D).children[0];
> >    var mesh2:Mesh = (obj2object3d as ObjectContainer3D).children[0];
> >    var mesh3:Mesh = (obj3object3d as ObjectContainer3D).children[0];
> >    //trace(mesh1.vertices.length);
> > }
>
> > private function initLights():void
> > {
> >    light = new DirectionalLight3D({x:1, y:1, z:-1, ambient:0.0});
> >    scene.addChild(light);
> > }
>
> > private function initListeners():void
> > {
> >    textBut.addEventListener( MouseEvent.MOUSE_DOWN, txtButMouseDown );
> >    stage.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
> >    stage.addEventListener( MouseEvent.MOUSE_UP, onMouseUp );
> >    addEventListener( Event.ENTER_FRAME, onEnterFrame );
> > }
>
> > private function onMouseDown(e:MouseEvent):void
> > {
> >    lastzoom = cZoom;
> >    lastMouseYzoom = stage.mouseY;
> >    lastPanAngle = camera.targetpanangle;
> >    lastMouseX = stage.mouseX;
> >    move = true;
> > }
>
> > private function txtButMouseDown(event:MouseEvent):void
> > {
> >    if(objtoload == 3){objtoload=0}
> >    objtoload+=1;
> >    trace("objtoload "+objtoload)
> >    if (objtoload==1){
> >            trace("objtoload load 1");
> >            obj2.visible=false;
> >            view.render();
> >            obj3.visible=false;
> >            view.render();
> >            obj1.visible=true;
> >            view.render();}
> >    if (objtoload==2){
> >            trace("objtoload load 2");
> >            obj3.visible=false;
> >            view.render();
> >            obj1.visible=false;
> >            view.render();
> >            obj2.visible=true;
> >            view.render();}
> >    if (objtoload==3){
> >            trace("objtoload load 3");
> >            obj2.visible=false;
> >            view.render();
> >            obj1.visible=false;
> >            view.render();
> >            obj3.visible=true;
> >            view.render();}
>
> >    /*****  this section didn't work either
> >    if (objtoload==1) {
> >            scene.addChild(obj1);
> >            scene.removeChild(obj2);
> >            scene.removeChild(obj3); }
> >    if (objtoload==2) {
> >            scene.addChild(obj2);
> >            scene.removeChild(obj1);
> >            scene.removeChild(obj3); }
> >    if (objtoload==3) {
> >            scene.addChild(obj3);
> >            scene.removeChild(obj2);
> >            scene.removeChild(obj1); }
> >                               ******************************/
>
> >    //trace("button "+"obj1 state="+obj1.visible)
> >    //trace("button "+"obj2 state="+obj2.visible)
> >    //trace("button "+"obj3 state="+obj3.visible)
> > }
>
> > private function onMouseUp(e:MouseEvent):void
> > {
> >    move = false;
> > }
>
> > private function onEnterFrame( e:Event ):void
> > {
> >    var cameraSpeed:Number = 0.8;
> >    //obj2.visible=true;
> >    if (move)
> >    {
> >    camera.targetpanangle = cameraSpeed*(stage.mouseX - lastMouseX) +
> > lastPanAngle;
> >    cZoom = 0.03*cameraSpeed*(stage.mouseY - lastMouseYzoom) + lastzoom;
> >    if(cZoom > 8)
> >    {
> >    cZoom = 7.9;
> >    }
> >    if(cZoom < 1)
> >    {
> >    cZoom = 1.1;
> >    }
> >    camera.zoom=cZoom;
> >    camera.hover();
> >    scene.updateTime();
> >    view.render();
> >    }
> > }
>
> > private function onResize(event:Event):void
> > {
> >    view.x = stage.stageWidth / 2;
> >                view.y = stage.stageHeight / 2;
> > }
>
> > }
> > }
>
> > On Apr 25, 3:55 am, richardolsson <[email protected]> wrote:
> >> Do you re-render after changing the visibility? Like so:
>
> >> myView.render();
>
> >> Cheers
> >> /R
>
> >> On Apr 25, 11:16 am, jojo <[email protected]> wrote:
>
> >>> I have 3 .obj files I load in and want to (for now) simply scroll  
> >>> thru
> >>> displaying/hiding them using a button. When I try to hide/show them
> >>> with obj1.visible=false; or obj1.visible=true; via button it simply
> >>> does not work.
>
> >>> //loading 3 files
> >>> obj1 = Obj.load("obj1.obj")
> >>> obj2 = Obj.load("obj1.obj")
> >>> obj3 = Obj.load("obj1.obj")
>
> >>> //add 1st to the scene only
> >>> scene.addChild(obj1);
>
> >>> //create a button
> >>> textBut=new Button();
> >>> addChild(textBut);
>
> >>> // button listener
> >>> textBut.addEventListener( MouseEvent.MOUSE_DOWN, txtButMouseDown );
>
> >>> //button handler to scroll thru objects ensuring 2 are removed and 1
> >>> added
> >>> if(objtoload == 3){objtoload=0}
> >>> objtoload=objtoload+1;
>
> >>> if (objtoload==1){
> >>>         trace("objtoload load 1");
> >>>         obj2.visible=false;
> >>>         obj3.visible=false;
> >>>         obj1.visible=true;}
> >>> if (objtoload==2){
> >>>         trace("objtoload load 2");
> >>>         obj3.visible=false;
> >>>         obj1.visible=false;
> >>>         obj2.visible=true;}
> >>> if (objtoload==3){
> >>>         trace("objtoload load 3");
> >>>         obj2.visible=false;
> >>>         obj1.visible=false;
> >>>         obj3.visible=true;}
>
> >>> nothing done in the onEnterFrame, however ... hmm ...
>
> >>> I think the logic of swapping is solid (the traces of objtoload look
> >>> good) so maybe the fact nothing is done in onEnterFrame is making it
> >>> fail?
>
> >>> The failure mode is obj1 displays and on button press obj1 stays and
> >>> nothing else appears. No compile or runtime errors. Subsequent  
> >>> button
> >>> clicks increments objtoload (1 to 3) but nothing displays except  
> >>> obj1.
>
> >>> I uploaded the little project (with assets) into the group upload  
> >>> area
> >>> as Test67.zip if anyone wants to try it for me ...
>
> >>>http://groups.google.com/group/away3d-dev/web/Test67.zip
>
> >>> Thanks in advance.- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Reply via email to