【问题标题】:1009: Cannot access a property or method of a null object reference1009:无法访问空对象引用的属性或方法
【发布时间】:2013-05-19 09:20:51
【问题描述】:

我已经被这样的错误困住了 2 天了,但是我从以前关于这个错误的问题的数量中搜索解决这个问题,我似乎仍然无法让它工作,主要是因为我完全看不懂。

这是我的代码:

package {

    import flash.events.*;
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import org.libspark.flartoolkit.support.pv3d.FLARBaseNode;
    import org.papervision3d.objects.parsers.DAE;
    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cone;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.materials.MovieAssetMaterial;
    import org.papervision3d.events.FileLoadEvent;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.core.proto.MaterialObject3D;
    import org.papervision3d.objects.primitives.Cube;

    [SWF(width=640, height=530, backgroundColor=0x808080, frameRate=30)]

    public class Earth extends PV3DARApp {

        private var _earth:DAE;
        private var _teapot:DAE;
        private var _bone:DAE;

        protected var _baseNode:FLARBaseNode

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

        private function _onInit(e:Event):void {

            bulet.addEventListener(MouseEvent.CLICK, _tombolbulet);
            teapot.addEventListener(MouseEvent.CLICK, _tombolteapot);
            tulang.addEventListener(MouseEvent.CLICK, _tomboltulang);

            addChild(bulet);
            addChild(teapot);
            addChild(tulang);


            _earth = new DAE();
            _earth.load('model/earth.dae');
            _earth.scale = 10;
            _earth.rotationX = 90;
            //_markerNode.addChild(_earth);

            _teapot = new DAE();
            _teapot.load('model/teapot.DAE');
            _teapot.scale = 10;
            _teapot.rotationX = 90;
            //_markerNode.addChild(_teapot);

            _bone = new DAE();
            _bone.load('model/bone.DAE');
            _bone.scale = 10;
            _bone.rotationX = 90;
            //_markerNode.addChild(_bone);

            function _tombolbulet (event:MouseEvent):void
            {   
                remove_all();
                _baseNode.addChild(_earth);

            }

            function _tombolteapot (event:MouseEvent):void
            {   
                remove_all();
                _baseNode.addChild(_teapot);

            }

            function _tomboltulang (event:MouseEvent):void
            {   
                remove_all();
                _baseNode.addChild(_bone);

            }

            function remove_all () : void
            {   
                _baseNode.removeChild(_earth);
                _baseNode.removeChild(_teapot);
                _baseNode.removeChild(_bone);

            }

            //addEventListener(Event.ENTER_FRAME, _update);
        }

        /*private function _update(e:Event):void {
            _earth.rotationZ += 0.5
            _teapot.rotationZ += 0.5
            _bone.rotationZ += 0.5
        }*/
    }
}

【问题讨论】:

    标签: actionscript-3 flash


    【解决方案1】:

    您应该首先为您的孩子调用new DAE(),然后通过addChild() 添加他们,反之亦然。此外,没有声明 bulet,但有 bone。此外,您删除了remove_all() 中的所有孩子,而其中一次似乎只有一个出现在屏幕上。此外,您还有很多命名错误的变量,这会弄乱代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 2013-05-16
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多