将String类型的值隐式强制转换为不相关的类型BitmapData

时间:2014-06-11 14:41:01

标签: actionscript-3 flash papervision3d flartoolkit

我是PaperVision3d和FLARToolkit(通常是AS3)的新手。我在youtube上做了一个关于如何创建增强现实应用的啧啧。我收到了错误

Function does not have a body. 

return value for function 'loop' has no type declaration.    

在私有函数循环上。我真的不知道我做错了什么。 PLZ帮助!!

代码

package
{
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Camera;
import flash.media.Video;
import flash.utils.ByteArray;

import org.libspark.flartoolkit.core.FLARCode;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
import org.libspark.flartoolkit.support.alternativa3d.FLARCamera3D;
import org.libspark.flartoolkit.support.pv3d.FLARBaseNode;
import org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

[SWF(width="640", height="480", frameRate="30", backgroundColor="#ffffff")]
public class testweb extends Sprite
{
    [Embed(source="earth.pat", mimeType="application/octet-stream")]
    private var marker:Class;

    [Embed(source="camera_para.dat", mimeType="application/octet-stream")]
    private var cam_params:Class;

    //createFLAR variables
    private var ar_params:FLARParam;
    private var ar_marker:FLARCode;
    //createCam variables
    private var ar_vid:Video
    private var ar_cam:Camera
    //createBMP vairiables
    private var ar_bmp:BitmapData;
    private var ar_raster:FLARRgbRaster_BitmapData;
    private var ar_detection:FLARSingleMarkerDetector;
    //createPapervision variables
    private var ar_scene:Scene3D;
    private var ar_3dcam:org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
    private var ar_basenode:FLARBaseNode;
    private var ar_viewport:Viewport3D;
    private var ar_renderengine:BasicRenderEngine;
    private var ar_transmat:FLARTransMatResult;
    private var ar_cube:Cube;

    public function testweb()
    {
        createFLAR();
        createCam();
        createBMP();
        createPapervision();
        addEventListener(Event.ENTER_FRAME, loop);
    }
    public function createFLAR()
    {
        ar_params= new FLARParam();
        ar_marker= new FLARCode(16,16);
        ar_params.loadARParam(new cam_params() as ByteArray);
        ar_marker.loadARPatt(new marker()); 
    }
    public function createCam()
    {
        ar_vid= new Video(640, 480);
        ar_cam= Camera.getCamera();
        ar_cam.setMode(640,480,30);
        ar_vid.attachCamera(ar_cam);
        addChild(ar_vid);
    }
    public function createBMP()
    {
        ar_bmp= new BitmapData(640,480);
        ar_bmp.draw(ar_vid);
        ar_raster= new FLARRgbRaster_BitmapData(ar_bmp);
        ar_detection= new FLARSingleMarkerDetector(ar_params, ar_marker,80);        
    }
    public function createPapervision()
    {
        ar_scene= new Scene3D();
        ar_3dcam= new org.libspark.flartoolkit.support.pv3d.FLARCamera3D(ar_params);
        ar_basenode= new FLARBaseNode();
        ar_renderengine= new BasicRenderEngine();
        ar_transmat= new FLARTransMatResult();

        var ar_light:PointLight3D= new PointLight3D();
        ar_light.x= 1000;
        ar_light.y= 1000;
        ar_light.z= -1000;

        var ar_bitmap:BitmapFileMaterial;
        ar_bitmap=new BitmapFileMaterial ("LBP2.jpg");
        ar_bitmap.doubleSided=true;

        ar_cube=new Cube(new MaterialsList({all:ar_bitmap}), 80, 80, 80);
        ar_scene.addChild(ar_basenode);
        ar_basenode.addChild(ar_cube);
        addChild(ar_viewport);
    }

    private function loop(e:Event);void
    {
        ar_bmp.draw(ar_vid);
        ar_cube.rotationX +=4;
        ar_cube.rotationY +=6;

        try
        {
            if(ar_detection.detectMarkerLite(ar_raster, 80) && ar_detection.getConfidence()>0.5)
            {
                ar_detection.getTransformMatrix(ar_transmat);
                ar_basenode.setTransformMatrix(ar_transmat);
                ar_renderengine.renderLayers(ar_scene, ar_3dcam, ar_viewport);
            }
        }

        catch (e:Error){}
    }

}

}

2 个答案:

答案 0 :(得分:2)

这看起来像一个错字。在行

private function loop(e:Event);void

将分号更改为冒号,如下所示:

private function loop(e:Event):void

答案 1 :(得分:1)

更改

private function loop(e:Event);void

private function loop(e:Event):void