clone a mesh with its EventListeners

Software: Away3D 4.x

veggieman25, Newbie
Posted: 05 February 2016 06:02 AM   Total Posts: 12

Hi all I have a question, I want to clone a mesh x number of times
with either newMesh.clone(); or putting Loader3D in a function a recalling it (see code).

How can I maintain the click event on each newMesh and a reference? So when I click on a newMesh it returns

“newMesh x was clicked”

I am think of using an array for this but not sure how to store a mesh in an array while keeping its EventListener.

The code.

AssetLibrary.enableParser(AWD2Parser);
var 
modelLoaderLoader3D = new Loader3D();
modelLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
modelLoader.addEventListener(LoaderEvent.LOAD_ERRORonLoadError);
modelLoader.addEventListener(AssetEvent.ASSET_COMPLETEf_onAssetComplete);
modelLoader.load(new URLRequest('box.awd'));

function 
f_onAssetComplete(eventAssetEvent): void
{
 
if (event.asset.assetType == AssetType.MESH)
 
{
  
var newMeshMesh event.asset as Mesh;
  
newMesh.mouseEnabled true;
  
newMesh.mouseChildren true;
  
newMesh.addEventListener(MouseEvent3D.CLICKf_modelLoader);
  
newMesh.geometry.scale(7);
  
_view.scene.addChild(newMesh);
 
}//end if
}//end f_onAssetComplete
function onResourceComplete(evLoaderEvent): void
{
 trace
("onResourceComplete");
 
modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
 
modelLoader.removeEventListener(LoaderEvent.LOAD_ERRORonLoadError);
}

function onLoadError(evLoaderEvent): void
{
 trace
("onLoadError");
 
modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
 
modelLoader.removeEventListener(LoaderEvent.LOAD_ERRORonLoadError);
 
modelLoader null;
}
function f_modelLoader(eventMouseEvent3D): void
{
 trace
("Mesh " +theMeshId " Was clicked");
   

rdoi, Member
Posted: 05 February 2016 05:41 PM   Total Posts: 86   [ # 1 ]

All Object3D have an “id”, “name” and “extra” property that you can set. The id is more specific and may be set by a loader or assetmanager. The name is any string. And “extra” is a user data that can store any kind of arbitrary data you need. You can use it to store an unique ID or index.

And, as any event, MouseEvent3D have a “target” property that points to the instance that triggered the event.

So, if you set a yourMesh.extra=“id123” in your clone, you can retrieve it in your event handler as Mesh(event.target).extra .

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X