Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I determine which image was clicked in 3D carousel?

New Here ,
Jul 25, 2013 Jul 25, 2013

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>

TOPICS
ActionScript
656
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 25, 2013 Jul 25, 2013

check the properties of InteractiveScene3DEvent to see how to access the pressed object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2013 Jul 25, 2013

Your answer may be correct, but I am very much a beginner to actionscript, and I was wondering moreso if it is possible to determine the root/url (i.e. images/resolv2.jpg)? Or even if InteractiveScene3DEvent calls a variable that holds this url? However, specifically, I'm just wondering if the actionscript itself could determine the url in a line of code such as "if object == BitmapFileMaterial("/images/resolv2.jpg"); "? Also, here's a copy of InteractiveScene3DEvent in more detail if you think that will help:

public class InteractiveScene3DEvent extends Event

          {

                    /**

                     * Dispatched when a container in the ISM recieves a MouseEvent.CLICK event

                    * @eventType mouseClick

                    */

                    public static const OBJECT_CLICK:String = "mouseClick";

                    /**

                     * Dispatched when a container in the ISM receives an MouseEvent.MOUSE_OVER event

                    * @eventType mouseOver

                    */

                    public static const OBJECT_OVER:String = "mouseOver";

                    /**

                     * Dispatched when a container in the ISM receives an MouseEvent.MOUSE_OUT event

                    * @eventType mouseOut

                    */

                    public static const OBJECT_OUT:String = "mouseOut";

                    /**

                     * Dispatched when a container in the ISM receives a MouseEvent.MOUSE_MOVE event

                    * @eventType mouseMove

                    */

                    public static const OBJECT_MOVE:String = "mouseMove";

                    /**

                     * Dispatched when a container in the ISM receives a MouseEvent.MOUSE_PRESS event

                    * @eventType mousePress

                    */

                    public static const OBJECT_PRESS:String = "mousePress";

                    /**

                     * Dispatched when a container in the ISM receives a MouseEvent.MOUSE_RELEASE event

                    * @eventType mouseRelease

                    */

                    public static const OBJECT_RELEASE:String = "mouseRelease";

                    /**

                     * Dispatched when the main container of the ISM is clicked

                    * @eventType mouseReleaseOutside

                    */

                    public static const OBJECT_RELEASE_OUTSIDE:String = "mouseReleaseOutside";

                    /**

                     * Dispatched when a container is created in the ISM for drawing and mouse interaction purposes

                    * @eventType objectAdded

                    */

                    public static const OBJECT_ADDED:String = "objectAdded";

                    public var displayObject3D                                        :DisplayObject3D = null;

                    public var sprite                                                            :Sprite = null;

                    public var face3d                                                            :Triangle3D = null;

                    public var x                                                                      :Number = 0;

                    public var y                                                                      :Number = 0;

                    public var renderHitData:RenderHitData;

                    public function InteractiveScene3DEvent(type:String, container3d:DisplayObject3D=null, sprite:Sprite=null, face3d:Triangle3D=null,x:Number=0, y:Number=0, renderhitData:RenderHitData = null, bubbles:Boolean=false, cancelable:Boolean=false)

                    {

                              super(type, bubbles, cancelable);

                              this.displayObject3D = container3d;

                              this.sprite = sprite;

                              this.face3d = face3d;

                              this.x = x;

                              this.y = y;

                              this.renderHitData = renderhitData;

                    }

          }

Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2013 Jul 26, 2013
LATEST

you need to check the papervision api for the papervision version you are using.   those papervision classes are not part of the core actionscript api.

p.s. make sure you're not nesting named functions.  it looks like you have nested functions in toggler().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines