Tutorial: Making Your PV3D Object Interactive

Making Your PV3D Object Interactive Screenshot

Objective
  • Learn how to make your Papervision3D object interactive.
Prerequisite
Files Required
Let’s Get Started!

From the last tutorial where I loaded an external image using BitmapFileMaterial, you should have guessed that this tutorial is next to come. *lol~* The purpose of breaking them up into 2 separate tutorials is to modularise them, just like programming. πŸ˜‰

First off, we have to edit our viewport instance in the init3D function.

viewport = new Viewport3D( 0, 0, true, true );

The fourth parameter, “interactive”, determines whether the viewport should listen for Mouse events. Since we want to make things interactive, we pass in true for it.

[UPDATE]: With thanks to Marco for pointing this out, to show the hand cursor when rolling over interactive objects, you can add the following line after you create the viewport instance.

viewport.containerSprite.buttonMode = true;

Next up, in our createPlane function, we have to change the interactive property of the material that we created for the plane to be true as well.

material.interactive = true;

To listen for the events, we will add the event listener in the addEventListeners function:

plane.addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, __onPlaneClick );

(Note: Don’t forget to import the InteractiveScene3DEvent!)

To wrap things up, we have to create the new listener function __onPlaneClick, which for the purpose of this tutorial, navigates to my blog’s RSS feed. πŸ˜€

private function __onPlaneClick ( e:InteractiveScene3DEvent ):void 
{
	navigateToURL( new URLRequest("http://feeds.feedburner.com/flashmech"), "_blank" );
}
Final Note

At this point of writing, it seems that there’s no easy way to make use of useHandCursor. From my research online, probably the best way to do that is from Papervision 2’s tutorial of Advanced Interactivity 2.

Hope the guys over at Papervision3D will add this functionality into the engine soon. :)

About Flashmech

I have too many things in plans for my own good. But well, that's me. :) I love God, praise Him, and trust that He has the best plans in life for me.
This entry was posted in ActionScript, Flash Platform, PaperVision3D, Tutorials. Bookmark the permalink.

4 Responses to Tutorial: Making Your PV3D Object Interactive

  1. Marco says:

    This will enable the hand cursor for the viewport.

    viewport.containerSprite.buttonMode = true;

  2. flashmech says:

    Thanks Marco for the tip! πŸ˜€

  3. Pingback: Bookmarks about Interactive

  4. I want to make interactive movieclips with buttons, not just the viewport.
    Here’s some of my stuff: http://bit.ly/CtVgv