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 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("Mesh " +theMeshId + " Was clicked");
}