我使用以下代码创建了一个旋转立方体,并将位图添加为立方体的侧面。我想知道是否可以将影片剪辑分配为立方体的侧面,以便我可以与它们进行一些交互。
import flash.events.Event;
import flash.display.Bitmap;
import flash.display.BitmapData;
import org.papervision3d.cameras.CameraType;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
var cube : Cube;
var basicview : BasicView = new BasicView(640, 480, true, false, CameraType.FREE);
addChild(basicview);
var logo : Logo = new Logo( 0,0); //Bitmapdata (jpeg) exported as class Logo from library
var matFront : BitmapMaterial = new BitmapMaterial(logo);
var matBack : BitmapMaterial = new BitmapMaterial(logo);
var ml : MaterialsList = new MaterialsList();
ml.addMaterial(matFront, "front");
ml.addMaterial(matBack, "back");
ml.addMaterial(new ColorMaterial(0x551F92),"right");
ml.addMaterial(new ColorMaterial(0x431872),"bottom");
ml.addMaterial(new ColorMaterial(0x341359),"top");
ml.addMaterial(new ColorMaterial(0x7429C7),"left");
cube = new Cube(ml,200,200,200,5,5,5);
basicview.scene.addChild(cube);
basicview.camera.fov = 20;
addEventListener(Event.ENTER_FRAME, enterFrame);
function enterFrame(e:Event) : void
{
cube.yaw((320-mouseX)*0.01);
cube.pitch((240-mouseY)*0.01);
}
basicview.singleRender();
}
更新
我加了这个
var matFront : MovieMaterial = new MovieMaterial(new MV(),false,true);
matFront.interactive = true ;
MV
只是这个代码的正方形
package Scripts {
import flash.display.MovieClip;
import flash.events.*;
public class MV extends MovieClip
{
public function MV( )
{
buttonMode = true;
addEventListener(MouseEvent.CLICK,traceFunction);
}
private function traceFunction(ev:MouseEvent) {
trace("clicked");
}
}
}
为什么我点击有影片剪辑的一侧时没有任何交互?
更新 2
好的,我发现我必须添加这一行
basicview.viewport.interactive = true;
但是为什么即使在影片剪辑的一侧不可见时我也会进行交互。
我怎样才能避免它?