-
package {
-
import flash.display.Bitmap;
-
import flash.display.MovieClip;
-
import flash.events.MouseEvent;
-
import flash.filters.GlowFilter;
-
import org.papervision3d.materials.MovieMaterial;
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.primitives.Cube;
-
import org.papervision3d.events.InteractiveScene3DEvent;
-
-
public class Main extends PaperBase {
-
-
// This is the movieclip that we'll use as the texture.
-
private var movie:MovieClip = new MovieClip();
-
-
// This movieclip will be completley transparent and will hold the
-
// texture movieclip, then move it to the correct loaction under the mouse.
-
private var movieParent:MovieClip = new MovieClip();
-
-
// These are buttons that I'm going to add to the texture movieclip
-
private var button:MovieClip = new MovieClip();
-
private var showbutton:MovieClip = new MovieClip();
-
-
// A "MovieMaterial" will use a movieclip as a texture.
-
private var mat:MovieMaterial;
-
-
// The cube that we're going to texture..
-
private var cube:Cube;
-
-
// This will import the file "E:/Papervision/images/showtex.jpg" to the project, and
-
// store the data in "ButtonIm". (This is the "Show Movieclip" Button)..
-
[Embed(source = "E:/Papervision/images/showtex.jpg")] private var ButtonIm:Class;
-
-
public function Main() {
-
// Initiate, 400px wide, 400px tall..
-
init(400, 400);
-
}
-
-
override protected function init3d():void {
-
// - See the prepareMovieclip function. This just builds the movieclip called "movie".
-
// You can use ANY movie clip for this..
-
prepareMovieclip();
-
-
// Prepare out moviematerial. Make it animated and interactive.
-
mat = new MovieMaterial(movie, false, true);
-
mat.interactive = true;
-
-
// Zoom in a bit..
-
default_camera.zoom = 5;
-
-
// Prepare the cube.
-
cube = new Cube(new MaterialsList( { all: mat } ), 500, 500, 500, 4, 4, 4);
-
// Listen for when the mouse is moved over the cube.
-
// Trigger the mMove function when this happens.
-
cube.addEventListener( InteractiveScene3DEvent.OBJECT_MOVE, mMove);
-
-
// Add the cube to the scene.
-
default_scene.addChild(cube);
-
-
// The movieParent movieclip will hold the movieclip which is being used
-
// as the texture. It will then move depending on the mouse posirion.
-
movieParent.addChild(movie);
-
// Make it invisible.
-
movieParent.alpha = 0;
-
-
// Add the movieParent movieclip to the stage.
-
addChild(movieParent);
-
-
}
-
-
-
private function prepareMovieclip():void {
-
-
// - This code will set up our movieclip which is going to be used
-
// as the texture for the cube.
-
// Draw Outline:
-
movie.graphics.beginFill(0xFFFFFF);
-
movie.graphics.drawRect(0, 0, 500, 500);
-
movie.graphics.endFill();
-
movie.graphics.beginFill(0x000000);
-
movie.graphics.drawRect(0, 0, 10, 500);
-
movie.graphics.drawRect(490, 0, 10, 500);
-
movie.graphics.drawRect(0, 0, 500, 10);
-
movie.graphics.drawRect(0, 490, 500, 10);
-
movie.graphics.endFill();
-
-
// Draw Circular Button:
-
button.graphics.beginFill(0xBB0000);
-
button.graphics.drawCircle(0, 0, 50);
-
button.graphics.endFill();
-
button.x = 250;
-
button.y = 250;
-
button.buttonMode = true;
-
-
// Load bitmap button texture:
-
var Bim:Bitmap = new ButtonIm();
-
// Draw "Show Movieclip" Texture:
-
showbutton.graphics.beginBitmapFill(Bim.bitmapData);
-
showbutton.graphics.drawRect(0,0,100,30);
-
showbutton.graphics.endFill();
-
showbutton.buttonMode = true;
-
showbutton.x = 380;
-
showbutton.y = 450;
-
-
// Add the buttons to the movieclip
-
movie.addChild(showbutton);
-
movie.addChild(button);
-
-
// -- Listen for the buttons to be clicked --
-
button.addEventListener(MouseEvent.CLICK, mClickButton);
-
showbutton.addEventListener(MouseEvent.CLICK, showHide);
-
// --
-
}
-
-
private function showHide( e:MouseEvent ):void {
-
// The "Show Movieclip" button has been clicked
-
if (movieParent.alpha == 0) { // If it's invisible,
-
movieParent.alpha = 0.2; // Make it slightly visible.
-
}else {
-
movieParent.alpha = 0; // Or make it invisible again
-
}
-
}
-
-
private function mClickButton(e:MouseEvent):void {
-
// The cental round button has been clicked.
-
if(button.name == "on"){
-
button.filters = null;
-
button.name = "off"
-
}else {
-
button.filters = [new GlowFilter(0x000000, 1, 15, 15, 10, 1)];
-
button.name = "on";
-
}
-
}
-
-
private function mMove( e:InteractiveScene3DEvent ):void {
-
// This code is run when the mouse is moved on the cube.
-
// This will move the movieclip to the right place beneath
-
// the mouse.
-
movieParent.x = root.mouseX -e.x;
-
movieParent.y = root.mouseY -e.y;
-
}
-
-
override protected function processFrame():void {
-
// Spin our cube a bit.
-
cube.yaw(0.25);
-
cube.pitch(0.25);
-
}
-
-
-
}
-
}