How can I determine which image was clicked in 3D carousel?
I have been modifying some 3D carousel code that I found in hopes that I can get it such that when image "resolv2.jpg" (or any of my other images) is clicked on at the front of my carousel, it goes to a specific webpage. By just replacing "moveBack(event.target) from the toggler section of the code with "navigateToURL:(newURLRequest('http://google.com'), the target DOES sucessfully go to google when clicked on. However, I want to modify this code by altering the else statement to say something to the effect of "else if event.target (clicked on object) is 'resolv2.jpg' THEN go to google". So essentially, my question is how can I determine which image was clicked? Here is the entire code with the area I was altering bolded:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init();" backgroundGradientColors="[#000033, #000033]" backgroundGradientAlphas="[1.0, 1.0]">
<mx:Script>
<![CDATA[
//Import Papervision Classes
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import org.papervision3d.core.*;
import org.papervision3d.lights.PointLight3D;
import flash.filters.DropShadowFilter;
import caurina.transitions.*;
private var numOfItems:int = 5;
private var radius:Number = 600;
private var anglePer:Number = (Math.PI*2) / numOfItems;
//private var dsf:DropShadowFilter = new DropShadowFilter(10, 45, 0x000000, 0.3, 6, 6, 1, 3);
public var angleX:Number = anglePer;
public var dest:Number = 1;
private var theLight:PointLight3D;
//Papervision Engine
private var viewport:Viewport3D;
private var scene:Scene3D;
private var camera:Camera3D;
private var renderer:BasicRenderEngine;
private var planeArray:Array = new Array();
[Bindable]
public var object:Object;
private var arrayPlane:Object;
private var p:Plane;
//Initiation function
private function init():void
{
viewport = new Viewport3D(pv3dCanvas.width, pv3dCanvas.height, false, true);
pv3dCanvas.rawChildren.addChild(viewport);
viewport.buttonMode=true;
renderer = new BasicRenderEngine();
scene = new Scene3D();
camera = new Camera3D();
camera.zoom = 2;
createObjects();
addEventListeners();
}
//Create Objects function
private function createObjects():void{
for(var i:uint=1; i<=numOfItems; i++)
{
/* var shadow:DropShadowFilter = new DropShadowFilter();
shadow.distance = 10;
shadow.angle = 25; */
var bam:BitmapFileMaterial = new BitmapFileMaterial("images/resolv"+i+".jpg");
bam.oneSide = false;
bam.smooth = true;
bam.interactive = true;
p = new Plane(bam, 220, 200, 2, 2);
p.x = Math.cos(i*anglePer) * radius;
p.z = Math.sin(i*anglePer) * radius;
p.rotationY = (-i*anglePer) * (180/Math.PI) + 270;
scene.addChild(p);
//p.filters=[shadow];
p.extra={pIdent:"in"};
p.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, toggler);
planeArray = p;
}
// create lighting
theLight = new PointLight3D();
scene.addChild(theLight);
theLight.y = pv3dCanvas.height;
}
private function toggler(event:InteractiveScene3DEvent):void
{
// if the cube's position is "in", move it out else move it back
if (event.target.extra.pIdent == "in")
{
moveOut(event.target);
}
else
{
moveBack(event.target);
}
private function moveOut(object:Object):void
{
trace(object +" my object");
// for each cube that was not selected, remove the click event listener
for each (var arrayPlane:Object in planeArray)
{
if (arrayPlane != object)
{
arrayPlane.removeEventListener(InteractiveScene3DEvent.OBJECT_PRESS, toggler);
}
}
//right.enabled=false;
//left.enabled=false;
// move the selected cube out 1000 and rotate 90 degrees once it has finished moving out
Tweener.addTween(object, {scaleX:1.2, time:0.5, transition:"easeInOutSine", onComplete:rotateCube, onCompleteParams:[object]});
Tweener.addTween(object, {scaleY:1.2, time:0.5, transition:"easeInOutSine", onComplete:rotateCube, onCompleteParams:[object]});
// set the cube's position to "out"
object.extra = {pIdent:"out"};
// move the camera out 1000 and move it the to same y coordinate as the selected cube
//Tweener.addTween(camera, {x:1000, y:object.y, rotationX:0, time:0.5, transition:"easeInOutSine"});
}
private function moveBack(object:Object):void
{
// for each cube that was not selected, add the click event listener back
for each (var arrayPlane:Object in planeArray)
{
if (arrayPlane != object)
{
arrayPlane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, toggler);
}
}
// move the selected cube back to 0 and rotate 90 degrees once it has finished moving back
Tweener.addTween(object, {scaleX:1, time:0.5, transition:"easeInOutSine", onComplete:rotateCube, onCompleteParams:[object]});
Tweener.addTween(object, {scaleY:1, time:0.5, transition:"easeInOutSine", onComplete:rotateCube, onCompleteParams:[object]});
// set the cube's position to "in"
object.extra = {pIdent:"in"};
// move the camera back to its original position
//Tweener.addTween(camera, {x:0, y:1000, rotationX:-30, time:0.5, transition:"easeInOutSine"});
//right.enabled=true;
//left.enabled=true;
}
private function goBack():void
{
// for each cube that was not selected, add the click event listener back
for each (var arrayPlane:Object in planeArray)
{
if (arrayPlane != object)
{
arrayPlane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, toggler);
}
}
}
private function rotateCube(object:Object):void
{
//object.rotationX = 0;
//Tweener.addTween(object, {rotationZ:0, time:0.5, transition:"easeOutSine"});
}
private function addEventListeners():void{
this.addEventListener(Event.ENTER_FRAME, render);
}
//Enter Frame Listener function
private function render(e:Event):void{
renderer.renderScene(scene, camera, viewport);
camera.x = Math.cos(angleX) * 800;
camera.z = Math.sin(angleX) * 800;
}
private function moveRight():void
{
dest++;
Tweener.addTween(this, {angleX:dest*anglePer, time:0.5});
//goBack();
}
private function moveLeft():void
{
dest--;
Tweener.addTween(this, {angleX:dest*anglePer, time:0.5});
//goBack();
}
]]>
</mx:Script>
<mx:Canvas width="1014" height="661">
<mx:Canvas id="pv3dCanvas" x="503" y="20" width="400" height="204" borderColor="#110101" backgroundColor="#841414" alpha="1.0" backgroundAlpha="0.57">
</mx:Canvas>
<mx:Button x="804" y="232" label="right" id="right" click="moveRight(),goBack()"/>
<mx:Button x="582" y="232" label="left" id="left" click="moveLeft(),goBack()" />
</mx:Canvas>
</mx:Application>
