Rotating object using flash
Step-1 Open a new document and set its background color as black.
Step-2 Draw a rectangle line inside the stage as like below. Then pick slider from Windows à Components àUser Interface à Slider. Drag it to stage. It will be as movieclip. Here we want 4 slider and give its movieclip instance name as fieldOfView, speed, rotatey, rotatex respectively.
Step-3 You can edit the values of sliders by Windows à Components Inspector.
Step-4 Bring the pattern in a new layer on stage by imports it to library, arranges it as like below and groups it (ctrl + g). Change it to movieclip and name it as pattern and again change it to movieclip, then name it as container.
Step-5 Draw a rectangle with color fills above the pattern layer and apply mask by right click it on same layer on time line, then click mask.
Step-6 Finally it looks like below.
Step-7 Click out of stage and give code.view in properties box.
Step-8 Open a new action script file copy and paste the below coding and save it as view inside newly created code folder.
package code
{
import flash.events.Event;
import flash.display.MovieClip;
import flash.geom.PerspectiveProjection;
import flash.geom.Point;
import fl.events.SliderEvent;
public class view extends MovieClip
{
public function view()
{
// To set default field of view
var pp:PerspectiveProjection = new PerspectiveProjection();
pp.projectionCenter = new Point(container.x, container.y);
pp.fieldOfView = 75;
// To apply projector and rotation to container clip
container.transform.perspectiveProjection = pp;
container.rotatey = 45;
// Setup components
fieldOfView.addEventListener(SliderEvent.CHANGE, sliderChangeHandler);
rotatey.addEventListener(SliderEvent.CHANGE, sliderChangeHandler);
rotatex.addEventListener(SliderEvent.CHANGE, sliderChangeHandler);
// Animate the pattern at the frame rate…
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
protected function enterFrameHandler(event:Event):void
{
// Rotate the pattern movie clip inside the object
container.pattern.rotationZ += speed.value;
}
protected function sliderChangeHandler(event:SliderEvent):void
{
switch( event.currentTarget.name )
{
case “fieldOfView”:
// Update projector
var pp:PerspectiveProjection = new PerspectiveProjection();
pp.projectionCenter = new Point(container.x, container.y);
pp.fieldOfView = event.currentTarget.value;
// Apply projector to object
container.transform.perspectiveProjection = pp;
break;
case “rotatey”:
// Apply rotation to object
container.rotatey = event.currentTarget.value;
break;
case “rotatex”:
// TO move the object in z coordinate space
container.z = event.currentTarget.value;
break;
}
}
}
}
Now run the program.
No comments yet.