flash on 2010-4-7
This is a tuts plus flex test exercise to demonstrate
the use of custom contextMenu Items within Flex or
the wonderful WonderFL
box and textfield classes are examples of how to
programatically save time generating common
components with editable qualities
♥0 |
Line 91 |
Modified 2010-04-07 07:26:07 |
MIT License
archived:2017-03-20 13:02:30
ActionScript3 source code
/**
* Copyright lewis_c1986 ( http://wonderfl.net/user/lewis_c1986 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/u5ep
*/
/*
This is a tuts plus flex test exercise to demonstrate
the use of custom contextMenu Items within Flex or
the wonderful WonderFL
box and textfield classes are examples of how to
programatically save time generating common
components with editable qualities
*/
package
{
//papervision
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.events.InteractiveScene3DEvent;
//flash native
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.text.*; // this is bad practice
import flash.events.*; // it makes the movieclip
// bigger than it needs to be
import flash.display.Scene;
public class Main extends MovieClip
{
private var zoomIn:Boolean = true;
private var view:BasicView;
private var builtInBox:MovieClip = new MovieClip();
private var planeGroup: DisplayObject3D;
private var _frontPlane:MovieMaterial;
private var frontPlane:Plane;
public function Main()
{
// write as3 code here..
init();
planeGroup = new DisplayObject3D();
view = new BasicView(stage.stageWidth, stage.stageHeight,true, true);
view.camera.zoom = 1;
view.viewport.interactive = true;
addChild(view);
_frontPlane = new MovieMaterial(builtInBox,true,true,true);
_frontPlane.smooth = true;
_frontPlane.interactive = true;
frontPlane = new Plane(_frontPlane);
frontPlane.z = 1
planeGroup.addChild(frontPlane);
view.scene.addChild(planeGroup);
view.startRendering();
view.camera.zoom = 100;
addEventListener(Event.ENTER_FRAME, enterFrameHandler)
}
private function enterFrameHandler(evt:Event):void
{
if((view.camera.zoom <= 150) && (zoomIn))
{
if(view.camera.zoom >= 150)
zoomIn = false;
view.camera.zoom += 0.5;
}
else
{
if(view.camera.zoom <= 75)
zoomIn = true;
view.camera.zoom -= 0.5;
}
}
private function init():void
{
//add event listeners
addEventListener(Event.RESIZE, onResize);
//movie Clips
builtInBox.addChild(Box(0xcccccc));
builtInBox.addChild(textLabel("test","#000000"));
builtInBox.x = (stage.stageWidth / 2) - (builtInBox.width / 2); builtInBox.y = (stage.stageHeight / 2) - (builtInBox.height / 2);
//addChild(builtInBox);
}
private function onResize(evt:Event):void
{
builtInBox.x = (stage.stageWidth / 2) - (builtInBox.width / 2); builtInBox.y = (stage.stageHeight / 2) - (builtInBox.height / 2);
}
private function Box(color:uint):Shape
{
//common grey box
var greyBox:Shape = new Shape();
greyBox.graphics.beginFill(color);
greyBox.graphics.drawRect(0,0,100,50);
greyBox.graphics.endFill();
return greyBox;
}
private function textLabel(msg:String, color:String = "#ffffff", menu:Object = null):TextField
{
color = (color.length != 7) ? ("#ffffff") : (color);
var txt:TextField = new TextField();
txt.htmlText = "<font face=\"arial\" color=\""+color+"\" >"+msg+"<\/font>";
txt.autoSize = TextFieldAutoSize.CENTER;
txt.selectable = false; // because these are labels there is no need to make the text selectable
txt.contextMenu = ((menu != null) && (menu is ContextMenu)) ? (ContextMenu(menu)) : ( new ContextMenu());
txt.y = 14;
return txt;
}
}
}