2013-04-06 75 views
0

我在Mobile Actionscript Flash Builder項目中使用Away3D框架,並嘗試調試/在我的bb劇本上運行。當我通過Flash Builder運行/調試時(不是bb特定的playbook),一切都很好。當我嘗試運行我的實際設備/調試我得到以下錯誤:Away3D和BB Playbook

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at away3d.core.managers::Stage3DManager()[/Users/jesskeating/Documents/Adobe Flash Builder 4.6/3DMobile/src/away3d-core-fp11_4_0_9_gold(1)/src/away3d/core/managers/Stage3DManager.as:35]

at away3d.core.managers::Stage3DManager$/getInstance()[/Users/jesskeating/Documents/Adobe Flash Builder 4.6/3DMobile/src/away3d-core fp11_4_0_9_gold(1)/src/away3d/core/managers/Stage3DManager.as:45]

at away3d.containers::View3D/onAddedToStage()[/Users/jesskeating/Documents/Adobe Flash Builder 4.6/3DMobile/src/away3d-core-fp11_4_0_9_gold(1)/src/away3d/containers/View3D.as:762]

at flash.display::DisplayObjectContainer/addChild() at Main/setupScene([/Users/jesskeating/Documents/Adobe Flash Builder 4.6/3DMobile/src/Main.as:85]

at Main()[/Users/jesskeating/Documents/Adobe Flash Builder 4.6/3DMobile/src/Main.as:79]

我知道空對象引用意味着我需要聲明/定義一個變種,但由於在使用Flash Builder完美運行的應用程序我不明白。

任何幫助將不勝感激。我的代碼如下...

package{ 
import away3d.containers.View3D; 
import away3d.entities.Mesh; 
import away3d.events.MouseEvent3D; 
import away3d.lights.DirectionalLight; 
import away3d.materials.ColorMaterial; 
import away3d.materials.SkyBoxMaterial; 
import away3d.materials.lightpickers.StaticLightPicker; 
import away3d.primitives.CubeGeometry; 
import away3d.primitives.SphereGeometry; 
import away3d.textures.BitmapCubeTexture; 
import away3d.textures.BitmapTexture; 

import flash.desktop.NativeApplication; 
import flash.display.SimpleButton; 
import flash.display.Sprite; 
import flash.display.StageAlign; 
import flash.display.StageScaleMode; 
import flash.events.*; 
import flash.events.AccelerometerEvent; 
import flash.geom.Vector3D; 
import flash.sensors.Accelerometer; 
import flash.text.*; 


[SWF(width=1024, height=600, frameRate=60)] 


public class Main extends Sprite{ 

    [Embed(source="dice.png")] 
    private var Dice:Class; 
    [Embed(source="alum-01.png")] 
    private var Alum:Class; 
    [Embed(source="bat-01.png")] 
    private var Bat:Class; 
    [Embed(source="brun-01.png")] 
    private var Brun:Class; 
    [Embed(source="julie-01.png")] 
    private var Julie:Class; 
    [Embed(source="slice-01.png")] 
    private var Slice:Class; 

    private var format:TextFormat; 
    private var inst:TextField; 

    private var myview:View3D = new View3D();; 
    private var dice:Mesh; 
    private var slice:Mesh; 
    private var bat:Mesh; 
    private var brun:Mesh; 
    private var julie:Mesh; 
    private var alum:Mesh; 

    private var acc1:Accelerometer; 
    private var acc2:Accelerometer; 
    private var acc3:Accelerometer; 

    private var knife:Mesh; 

    public function Main(){ 
     super(); 

     // support autoOrients 
     stage.align = StageAlign.TOP_LEFT; 
     stage.scaleMode = StageScaleMode.NO_SCALE; 

     format = new TextFormat(); 
     format.size = 26; 
     format.color = 0xFFFFFF; 
     inst = new TextField; 

     inst.defaultTextFormat = format; 
     inst.text = "Click on the cube you want to learn the cut of!" 
     addChild(inst); 
     inst.x = 250; 
     inst.y = 300; 
     inst.width = 500; 
     setupScene(); 
    } 

    private function setupScene():void{ 
     //adding the view for 3D 
     //myview = new View3D(); 
     addChild(myview); 

     var tdice:BitmapCubeTexture = new BitmapCubeTexture(new Dice().bitmapData, 
      new Dice().bitmapData, 
      new Dice().bitmapData, 
      new Dice().bitmapData, 
      new Dice().bitmapData, 
      new Dice().bitmapData); 

     var tslice:BitmapCubeTexture = new BitmapCubeTexture(new Slice().bitmapData, 
      new Slice().bitmapData, 
      new Slice().bitmapData, 
      new Slice().bitmapData, 
      new Slice().bitmapData, 
      new Slice().bitmapData); 

     var tbat:BitmapCubeTexture = new BitmapCubeTexture(new Bat().bitmapData, 
      new Bat().bitmapData, 
      new Bat().bitmapData, 
      new Bat().bitmapData, 
      new Bat().bitmapData, 
      new Bat().bitmapData); 

     var tbrun:BitmapCubeTexture = new BitmapCubeTexture(new Brun().bitmapData, 
      new Brun().bitmapData, 
      new Brun().bitmapData, 
      new Brun().bitmapData, 
      new Brun().bitmapData, 
      new Brun().bitmapData); 

     var tjulie:BitmapCubeTexture = new BitmapCubeTexture(new Julie().bitmapData, 
      new Julie().bitmapData, 
      new Julie().bitmapData, 
      new Julie().bitmapData, 
      new Julie().bitmapData, 
      new Julie().bitmapData); 

     var talum:BitmapCubeTexture = new BitmapCubeTexture(new Alum().bitmapData, 
      new Alum().bitmapData, 
      new Alum().bitmapData, 
      new Alum().bitmapData, 
      new Alum().bitmapData, 
      new Alum().bitmapData); 
     //making the shapes, adding cube to stage 
     dice = new Mesh(new CubeGeometry(), new SkyBoxMaterial(tdice)); 
     myview.scene.addChild(dice); 
     dice.x = -270; 
     dice.y = 150; 

     slice = new Mesh(new CubeGeometry(), new SkyBoxMaterial(tslice)); 
     myview.scene.addChild(slice); 
     slice.x = 0; 
     slice.y = 150; 

     bat = new Mesh(new CubeGeometry(), new SkyBoxMaterial(tbat)); 
     myview.scene.addChild(bat); 
     bat.x = 250; 
     bat.y = 150; 

     brun = new Mesh(new CubeGeometry(), new SkyBoxMaterial(tbrun)); 
     myview.scene.addChild(brun); 
     brun.x = -270; 
     brun.y = -150; 

     julie = new Mesh(new CubeGeometry(), new SkyBoxMaterial(tjulie)); 
     myview.scene.addChild(julie); 
     julie.x = 0; 
     julie.y = -150; 

     alum = new Mesh(new CubeGeometry(), new SkyBoxMaterial(talum)); 
     myview.scene.addChild(alum); 
     alum.x = 270; 
     alum.y = -150; 

     //making the mouse work and click event on the cube 
     dice.mouseEnabled = true; 
     dice.addEventListener(MouseEvent3D.MOUSE_DOWN, function(event:MouseEvent3D):void{clickMe("Dice")}); 

     slice.mouseEnabled = true; 
     slice.addEventListener(MouseEvent3D.MOUSE_DOWN, function(event:MouseEvent3D):void{clickMe("Slice")}); 

     julie.mouseEnabled = true; 
     julie.addEventListener(MouseEvent3D.MOUSE_DOWN, function(event:MouseEvent3D):void{clickMe("Julienne")}); 

     bat.mouseEnabled = true; 
     bat.addEventListener(MouseEvent3D.MOUSE_DOWN, function(event:MouseEvent3D):void{clickMe("Batonnet")}); 

     brun.mouseEnabled = true; 
     brun.addEventListener(MouseEvent3D.MOUSE_DOWN, function(event:MouseEvent3D):void{clickMe("Brunoise")}); 

     alum.mouseEnabled = true; 
     alum.addEventListener(MouseEvent3D.MOUSE_DOWN, function(event:MouseEvent3D):void{clickMe("Alumette")}); 

     knife = new Mesh(new CubeGeometry, new ColorMaterial(0xFF0000)); 

     //setting how you look at the view 
     myview.camera.z = -500; 
     myview.camera.lookAt(new Vector3D()); 

     //adding the enter frame event for spinning 
     addEventListener(Event.ENTER_FRAME, loop); 
    } 

    private function loop(event:Event):void{ 

     //making the shapes rotate 
     dice.rotationY++; 
     slice.rotationY++; 
     alum.rotationY++; 
     julie.rotationY++; 
     bat.rotationY++; 
     brun.rotationY++; 

     //rendering the view 
     myview.render(); 
    } 

    private function clickMe(cutPicked:String):void{ 

     switch(cutPicked){ 
      case "Dice": 
       acc1.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate); 
       myview.scene.removeChild(dice); 
       myview.scene.removeChild(slice); 
       myview.scene.removeChild(alum); 
       myview.scene.removeChild(julie); 
       myview.scene.removeChild(bat); 
       myview.scene.removeChild(brun); 
       removeChild(inst); 

       myview.scene.addChild(knife); 
       //knife.rotateTo(10,10,0); 
       break; 
      case "Chiffonade": 
       //acc3.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate3); 
       myview.scene.removeChild(dice); 
       myview.scene.removeChild(slice); 
       myview.scene.removeChild(alum); 
       myview.scene.removeChild(julie); 
       myview.scene.removeChild(bat); 
       myview.scene.removeChild(brun); 
       removeChild(inst); 

       myview.scene.addChild(knife); 
       knife.x = -75; 
       break; 
      case "Slice": 
       //acc2.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate2); 
       myview.scene.removeChild(dice); 
       myview.scene.removeChild(slice); 
       myview.scene.removeChild(alum); 
       myview.scene.removeChild(julie); 
       myview.scene.removeChild(bat); 
       myview.scene.removeChild(brun); 
       removeChild(inst); 

       myview.scene.addChild(knife); 
       knife.x = -75; 
       break; 
      case "Alumette": 
       //acc2.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate2); 
       myview.scene.removeChild(dice); 
       myview.scene.removeChild(slice); 
       myview.scene.removeChild(alum); 
       myview.scene.removeChild(julie); 
       myview.scene.removeChild(bat); 
       myview.scene.removeChild(brun); 
       removeChild(inst); 

       myview.scene.addChild(knife); 
       knife.x = -75; 
       break; 
      case "Batonnet":      
       //acc2.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate2); 
       myview.scene.removeChild(dice); 
       myview.scene.removeChild(slice); 
       myview.scene.removeChild(alum); 
       myview.scene.removeChild(julie); 
       myview.scene.removeChild(bat); 
       myview.scene.removeChild(brun); 
       removeChild(inst); 

       myview.scene.addChild(knife); 
       knife.x = -75; 
       break; 
      case "Julienne": 
       //acc2.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate2); 
       myview.scene.removeChild(dice); 
       myview.scene.removeChild(slice); 
       myview.scene.removeChild(alum); 
       myview.scene.removeChild(julie); 
       myview.scene.removeChild(bat); 
       myview.scene.removeChild(brun); 
       removeChild(inst); 

       myview.scene.addChild(knife); 
       knife.x = -75; 
       break; 
      case "Brunoise": 
       //acc1.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate); 
       myview.scene.removeChild(dice); 
       myview.scene.removeChild(slice); 
       myview.scene.removeChild(alum); 
       myview.scene.removeChild(julie); 
       myview.scene.removeChild(bat); 
       myview.scene.removeChild(brun); 
       removeChild(inst); 

       myview.scene.addChild(knife); 
       knife.x = -75; 
     } 

     knife.mouseEnabled = true; 
     knife.addEventListener(MouseEvent3D.MOUSE_DOWN, up); 
    } 

    private function up(event:MouseEvent3D):void{ 
     if (Accelerometer.isSupported){ 
      acc1 = new Accelerometer(); 
      acc2 = new Accelerometer(); 
      acc3 = new Accelerometer(); 

      acc1.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate); 
     }else{ 
      // Handle case when the accelerometer is not supported here 
     } 
    } 

    private function onAccUpdate(e:AccelerometerEvent):void{ 
     var threshold:Number = 2; 
     if(e.accelerationY > threshold){ 
      knife.rotationX = 45; 
      if(knife.rotationX == 45){ 
       knife.rotationX = -45; 
      } 
     } 
     } 
    } 

}

+0

好吧,如果你試圖在便攜式設備上進行調試,可能是設備缺少資源來完成編譯?每次你在你的電腦上編譯所有的資源都可用,也許你的設備缺少外部庫。 – joshua 2013-04-07 06:23:48

+0

TypeError:錯誤#1009:無法訪問空對象引用的屬性或方法。這意味着該對象在它當時爲空來引用它,與聲明一個變量無關 – joshua 2013-04-07 06:26:03

+0

也許你應該在釋放FB時使用「專用包裝」 – 2013-04-07 09:39:52

回答

0

我不認爲BB劇本的版本AIR的支持Stage3D的,後來我聽見他們使用AIR 3.1。我看過他們計劃使用AIR 3.2或更高版本更新SDK,但不知道是否已經發生。