Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using prototypes in AS3 is discouraged. But there is a way to use it if you are compiling AS3 with the flex compiler.</p> <p>First, you need to give a few compiler options.</p> <p>PrototypeExtension-config.xml</p> <pre><code>&lt;flex-config&gt; &lt;compiler&gt; &lt;as3&gt;false&lt;/as3&gt; &lt;es&gt;true&lt;/es&gt; &lt;strict&gt;false&lt;/strict&gt; &lt;/compiler&gt; &lt;/flex-config&gt; </code></pre> <p>PrototypeExtension.as</p> <pre><code>package { import flash.display.Sprite; import flash.display.MovieClip; import flash.events.Event; import flash.geom.Point; import flash.utils.getTimer; public class PrototypeExtension extends Sprite { public function PrototypeExtension() { stage.align = "tl"; stage.scaleMode = "noScale"; MovieClip.prototype.move = function (x:int, y:int):void { this.x = x; this.y = y; }; MovieClip.prototype.tween = function (to:Point, duration:int):void { var start:int = getTimer(); var from:Point = new Point(this.x, this.y); var thisInstance:MovieClip = this; this.addEventListener(Event.ENTER_FRAME, function tweener(e:Event):void { var time:int = getTimer() - start; if (time &gt; duration) { thisInstance.move(to.x, to.y); thisInstance.removeEventListener(Event.ENTER_FRAME, tweener); } var t:Number = time / duration; t = t * (2 - t); var u:Number = 1 - t; thisInstance.move(u * from.x + t * to.x, u * from.y + t *to.y); }); } var mc:MovieClip = new MovieClip; mc.graphics.beginFill(0); mc.graphics.drawRect(0, 0, 100, 100); mc.graphics.endFill(); mc.tween(new Point(400, 300), 1000); addChild(mc); } } } </code></pre> <p>by</p> <p>mxmlc PrototypeExtension.as</p> <p>You can see how prototype extension is enabled in AS3.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload