How to wait until the DAE model loads on flash using PaperVision3d libaries?

577 Views Asked by At

i need to make a loader on flash or a simple label who say "wait, the model is loading". This is the part of my script were i load the model, but i have no idea how to control the loading process, thanks for any help.

Code:

    private function _onInit(e:Event):void {
        _earth = new DAE();
        _earth.load('model/hfarm.DAE');
        _earth.scale = 0.3;
        _earth.rotationX = 90;
        _markerNode.addChild(_earth);

        addEventListener(Event.ENTER_FRAME, _update);
    }

And the whole code:

package {

    import flash.events.Event;
    import org.papervision3d.objects.parsers.DAE;

    [SWF(width=640, height=480, backgroundColor=0xCCCCCC, frameRate=30)]

    public class Earth extends PV3DARApp {

        private var _earth:DAE;

        public function Earth() {
            addEventListener(Event.INIT, _onInit);
            init('Data/camera_para.dat', 'Data/flarlogo.pat');
        }

        private function _onInit(e:Event):void {
            _earth = new DAE();
            _earth.load('model/hfarm.DAE');
            _earth.scale = 0.3;
            _earth.rotationX = 90;
            _markerNode.addChild(_earth);

            addEventListener(Event.ENTER_FRAME, _update);
        }

        private function _update(e:Event):void {
            //_earth.rotationZ -= 1
        }
    }

}

2

There are 2 best solutions below

0
On

This can be done. Rough Code ->

import org.papervision3d.events.FileLoadEvent;

public var SOMEDAE:DisplayObject3D;

public someFunction():void{

  SOMEDAE = new Collada('modelpath.dae',null)

  SOMEDAE.addEventListener(FileLoadEvent.LOAD_COMPLETE, function():void {           
    // post load stuff
  });

  scene.addChild(SOMEDAE);

}
0
On

It would be nice if Papervision had a loading event but I don't believe so. The model has a .loaded property so perhaps it'll work to check that each frame to see if the load is complete.