This is a refiend post from an earlier one, with more info:
http://away3d.com/forum/viewthread/4597/
Basically, when using Stage3DProxy (needed when integrating Starling), the MouseEvent3D system acts incorrectly on mobile (iOS/Android). MouseEvent3D’s don’t seem to fire on the first click. Instead, they require 2 clicks - the first to “get focus”, it seems. And the second to call the event. If you click back-and-forth between objects, it appears to do nothing - you need to click one object at least 2 successive times.
I’m attaching the simple code below (first the broken version, with Stage3DProxy and then a working version without). Thanks for any thoughts or suggestions!
// Stage3D Proxy - incorrect on mobile
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Vector3D;
import away3d.containers.View3D;
import away3d.core.managers.Stage3DManager;
import away3d.core.managers.Stage3DProxy;
import away3d.entities.Mesh;
import away3d.events.MouseEvent3D;
import away3d.events.Stage3DEvent;
import away3d.materials.ColorMaterial;
import away3d.primitives.CubeGeometry;
[SWF(width=320,height=480,frameRate=60)]
public class JunkProject extends Sprite {
private var view:View3D;
private var stage3DManager : Stage3DManager;
private var stage3DProxy : Stage3DProxy;
public function JunkProject()
{
super();
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage3DManager = Stage3DManager.getInstance(stage);
// Create a new Stage3D proxy to contain the separate views
stage3DProxy = stage3DManager.getFreeStage3DProxy();
stage3DProxy.configureBackBuffer(stage.fullScreenWidth,stage.fullScreenHeight,2,true);
stage3DProxy.addEventListener(Stage3DEvent.CONTEXT3D_CREATED, onContextCreated);
stage3DProxy.color = 0x0;
}
protected function onContextCreated(Stage3DEvent:Event):void {
view = new View3D();
view.stage3DProxy = stage3DProxy;
view.shareContext = true;
addChild(view);
view.camera.position = new Vector3D(0,700,0);
view.camera.lookAt(new Vector3D());
// cube 1
var colorMaterial1:ColorMaterial = new ColorMaterial(0x0000FF);
var cube1:Mesh = new Mesh (new CubeGeometry(100,100,100), colorMaterial1);
cube1.position = new Vector3D(0,0,0);
cube1.mouseEnabled = true;
cube1.addEventListener( MouseEvent3D.CLICK, onCubeClick );
view.scene.addChild(cube1);
// cube 2
var colorMaterial2:ColorMaterial = new ColorMaterial(0x00FF00);
var cube2:Mesh = new Mesh (new CubeGeometry(100,100,100),colorMaterial2);
cube2.position = new Vector3D(150,0,0);
view.scene.addChild(cube2);
cube2.mouseEnabled = true;
cube2.addEventListener( MouseEvent3D.CLICK, onCubeClick );
addEventListener(Event.ENTER_FRAME, gameLoop);
}
protected function gameLoop(e:Event):void {
stage3DProxy.clear();
view.render();
stage3DProxy.present();
}
private function onCubeClick(e:MouseEvent3D):void {
Mesh(e.target).rotationX += 20;
}
}
}
// Without Stage3D Proxy - correct on mobile
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Vector3D;
import away3d.containers.View3D;
import away3d.entities.Mesh;
import away3d.events.MouseEvent3D;
import away3d.materials.ColorMaterial;
import away3d.primitives.CubeGeometry;
[SWF(width=320,height=480,frameRate=60)]
public class JunkProject extends Sprite {
private var view:View3D;
public function JunkProject()
{
super();
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
init();
}
protected function init():void {
view = new View3D();
addChild(view);
view.camera.position = new Vector3D(0,700,0);
view.camera.lookAt(new Vector3D());
// cube 1
var colorMaterial1:ColorMaterial = new ColorMaterial(0x0000FF);
var cube1:Mesh = new Mesh (new CubeGeometry(100,100,100), colorMaterial1);
cube1.position = new Vector3D(0,0,0);
cube1.mouseEnabled = true;
cube1.addEventListener( MouseEvent3D.CLICK, onCubeClick );
view.scene.addChild(cube1);
// cube 2
var colorMaterial2:ColorMaterial = new ColorMaterial(0x00FF00);
var cube2:Mesh = new Mesh (new CubeGeometry(100,100,100),colorMaterial2);
cube2.position = new Vector3D(150,0,0);
view.scene.addChild(cube2);
cube2.mouseEnabled = true;
cube2.addEventListener( MouseEvent3D.CLICK, onCubeClick );
addEventListener(Event.ENTER_FRAME, gameLoop);
}
protected function gameLoop(e:Event):void {
view.render();
}
private function onCubeClick(e:MouseEvent3D):void {
Mesh(e.target).rotationX += 20;
}
}
}