I was in need of a subclass of MovieClip that could rewind and forward with a simple method call. That is the result. You can specify a callback function to call after the timeline playhead cease moving. It is very raw at the moment, i am still learning. Any suggestion or modification to the code is greatly appreciated.
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class AdvancedMovieClip extends MovieClip {
var dir:String = null;
var _targetframe:Number;
var _callback:Function = new Function();
var _params:Object = null;
var _numberOfFrames:Number;
public function AdvancedMovieClip():void {
super();
_numberOfFrames = this.totalFrames;
}
public function block() {
removeEventListener(Event.ENTER_FRAME, enterframeHandler);
}
public function forward(targetframe:Number = 25, callback:Function = null, params:Object = null):void {
dir = "forward";
_callback = callback;
_params = params;
_targetframe = (targetframe == 25) ? this.totalFrames : targetframe;
addEventListener(Event.ENTER_FRAME, enterframeHandler);
}
public function backward(targetframe:Number = 1, callback:Function = null, params:Object = null):void {
dir = "backward";
_callback = callback;
_params = params;
_targetframe = (targetframe == 1) ? 1 : targetframe;
addEventListener(Event.ENTER_FRAME, enterframeHandler);
}
private function enterframeHandler(e:Event):void {
switch(dir) {
case "forward":
((this.currentFrame == this.totalFrames) || (this.currentFrame == _targetframe)) ? (stopMovement()) : this.nextFrame();
break;
case "backward":
((this.currentFrame == 1) || (this.currentFrame == _targetframe)) ? (stopMovement()) : this.prevFrame();
break;
}
}
private function stopMovement() {
removeEventListener(Event.ENTER_FRAME, enterframeHandler);
if (_callback != null) {
_callback(_params);
}
}
}
}
Hi to all!
Around christmas, Santa on his trip from the south pole around the world, left us the public alpha release of the papervision 3d engine for flash. After being on it for days, i found that, with this release, some things were changed. Today i’m going to talk about the renderScene method of the viewport class.
In the old papervision way, for rendering a camera, you only had to use the renderCamera method of the camera object. This has been changed in a fashionable way.
First you have to define a viewport. Then add it as a child to the container you want, that can be a MovieClip, a Sprite or what else.
var viewport:Viewport3D = new Viewport3D(0, 0, true, false);
addChild(viewport);
Then create your rendering engine, that is the object that really do take care of rendering your scene. So from now on, on Great White, you’ll have to render using the Renderer, not the Scene.
var renderer:BasicRenderEngine = new BasicRenderEngine();
Next step is creating the scene, and the camera (you can create both types, camera and freecamera).
var scene:Scene3D = new Scene3D();
var camera:FreeCamera3D = new FreeCamera3D();
Then go on for the real rendering trigger action. It’s up to you deciding how much often you’ll have to render your scene.
renderer.renderScene(scene, camera, viewport);
If you are wondering, as me, the right syntax for the Viewport3D constructor, it is:
public function Viewport3D(viewportWidth:Number = 640, viewportHeight:Number = 480, autoScaleToStage:Boolean = false, interactive:Boolean = false, autoClipping:Boolean = true, autoCulling:Boolean = true);
so remember:
- Create the viewport and attach it to the container
- Define a renderer.
- Define your camera and your scene.
- When you wish, feed the BasicRenderEngine.renderScene method with scene, camera and viewport.
I’ll write some other articles on the release, i hope nobody will hate me for this ;)
Have a nice day!
Amayeta SWF Encrypt 4.0 obfuscate code you write in Actionscript.
Well, it’s a great step ahead if it makes impossible for anyone on the net, playing with your game or surfing your site, to decompile your swf file. Well, i run a test on most of my stuff published with the trial version, freely downloadable from the site.
And the code is really obfuscated! Despite an error i got when i first open the fla gained by decompiling, it opens correctly. The trick shows right when i try to read the code on the keyframes or on the objects. It’s all messed up, in a way it’s impossible to recompile it :)
Great!
Thanks Amayeta! I think i’ll go on during the weekend with some test, and if i’ll be satisfied with the result, you have a new customer!
Have a nice weekend!
Testing in Fl-Fl-Flex and Papervision3d for me! I want the world to rotate on the Z axis. Crossing my fingers! Bye!
Once upon a time, i remember that in old actionscript 2 (it seems like it’s centuries away, aint it?) there were two main functions used to trigger events based on time. There were setInterval() and setTimeout(). While the first repeated the triggering continuosly at a certain interval, the latter, hidden in previous versions, fired the event at the interval and just died. That was good, but actually not good enough for being spared by the Update.
In Actionscript 3, we can use at this purpose the Timer class. It lives in the package named flash.utils. It has all we need for time based events and their triggering.
To use it, you have to import the flash.utils package thru the import directive. You can then call the constructor method, which expects you to provide the interval at which events are fired, expressed in milliseconds. There’s an optional second parameter, which specified the number of times the call will be made (0 being indefinitely). Obviously, thanks to this parameter, you can mimic the functionality of the old setTimeout() function, entering a 1.
Below you can find a simple example of the Timer class.
Nice timing ;)
// The package must be imported to be used. ALWAYS.
import flash.utils.*;
// Constructor is fired, and if will fire events every 500ms.
var myTimer:Timer = new Timer(500);
//Please listener at myTimer and everytime it fires its event, please call the timedFunction function
myTimer.addEventListener(”timer”, timedFunction);
// Get going!
myTimer.start();
// Print a nice phrase every time you are launched!
function timedFunction(eventArgs:TimerEvent) {
trace(”This is time n°” + myTimer.currentCount + ” i got triggered.”);
}
Next entries »