|
Bill7745, Newbie
Posted: 17 December 2015 07:23 PM Total Posts: 22
Hi I’m trying to move an imported object that I exported from PreFab2 as an as3 class with the mouse on a map for a war game. I tried enabling the mouse,
(_soldier.mouseEnabled = true;),
and using a MouseEvent3D,(_soldier.addEventListener(MouseEvent3D.MOUSE_DOWN,_soldierOnMouseDown);,
but I can’t select the object.
What do I need to do to select the imported object so I can move it around on a map?
|
veggieman25, Newbie
Posted: 03 February 2016 10:12 AM Total Posts: 12
[ # 1 ]
Hi all new to away3d, running Away3D 4.1.6
I am having the same issue with MousePicking on an imported object (awd file).
The mouse event is not working, any ideas?
|
rdoi, Member
Posted: 03 February 2016 04:35 PM Total Posts: 86
[ # 2 ]
You may be setting the event in the container, not in the mesh itself.
Post the code where you setup the event listeners.
|
veggieman25, Newbie
Posted: 03 February 2016 09:41 PM Total Posts: 12
[ # 3 ]
The texture is embeded in the awd file;
Parsers.enableAllBundled(); var modelLoader: Loader3D = new Loader3D(); modelLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete); modelLoader.addEventListener(LoaderEvent.LOAD_ERROR, onLoadError); modelLoader.load(new URLRequest('box.awd'));
modelLoader.mouseEnabled = true; modelLoader.addEventListener(MouseEvent3D.CLICK, f_modelLoader);
function onResourceComplete(ev: LoaderEvent): void { trace("onResourceComplete"); modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete); modelLoader.removeEventListener(LoaderEvent.LOAD_ERROR, onLoadError); _view.scene.addChild(modelLoader); }
function onLoadError(ev: LoaderEvent): void { trace("onLoadError"); modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete); modelLoader.removeEventListener(LoaderEvent.LOAD_ERROR, onLoadError); modelLoader = null; }
function f_modelLoader(event: MouseEvent3D): void { trace("hit"); }
|
rdoi, Member
Posted: 04 February 2016 02:02 PM Total Posts: 86
[ # 4 ]
Well you ARE setting the listener in the container.
Maybe you just need to set .mouseChildren= true;
If for some reason, mouse events on v4.x are not bubbled to containers, you will have to set the events in all internal meshes of your “box.awd”.
You can achieve this by looping all container’s children or by listening for loader’s AssetComplete event and assign a mouse listener when the asset type is a mesh.
|
veggieman25, Newbie
Posted: 04 February 2016 11:43 PM Total Posts: 12
[ # 5 ]
Thank you this worked
AssetLibrary.enableParser(AWD2Parser); var modelLoader: Loader3D = new Loader3D(); modelLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete); modelLoader.addEventListener(LoaderEvent.LOAD_ERROR, onLoadError); modelLoader.addEventListener(AssetEvent.ASSET_COMPLETE, f_onAssetComplete); modelLoader.load(new URLRequest('box.awd'));
function f_onAssetComplete(event: AssetEvent): void { if (event.asset.assetType == AssetType.MESH) { var newMesh: Mesh = event.asset as Mesh; newMesh.mouseEnabled = true; newMesh.mouseChildren = true; newMesh.addEventListener(MouseEvent3D.CLICK, f_modelLoader); newMesh.geometry.scale(7); _view.scene.addChild(newMesh); }//end if }//end f_onAssetComplete function onResourceComplete(ev: LoaderEvent): void { trace("onResourceComplete"); modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete); modelLoader.removeEventListener(LoaderEvent.LOAD_ERROR, onLoadError); }
function onLoadError(ev: LoaderEvent): void { trace("onLoadError"); modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete); modelLoader.removeEventListener(LoaderEvent.LOAD_ERROR, onLoadError); modelLoader = null; } function f_modelLoader(event: MouseEvent3D): void { trace("hit"); }
|