Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get MovieClip.prototype in ActionScript 3?
    primarykey
    data
    text
    <p>In a ActionScript 2 code sample it uses some MovieClip.prototype's functions, as MovieClip.prototype.setModel;</p> <p>I'm trying to write this example using an ActionScript 3 class, but the MoviewClip.prototype does not exists, where can I get it from? Does it exist in ActionScript 3?</p> <p><strong>--update</strong></p> <p>Ok, as you are asking, here goes, this code works just fine as an ActionScript included on frame1, but I want to make a ActionScript 3 class with this same code:</p> <pre><code>//package //{ // public class asteroids extends MovieClip // { var MW = 8; // Scaling factor for models (which were originally drawn on graph paper) var SW = Stage.width; // Stage coords var SH = Stage.height; var kDegToRad = Math.PI/180; // Useful constant for drawing circles &amp; such var kDamp = 0.99; // Damping in ship acceleration // The models // // Rocket fuselage var fuseModel = [{mx:0, my:-5.5, x:0, y:-4, pen:.5, clr:0x000033, alpha:50}, {cx:-1,cy:-3,x:-1,y:-1, pen:2, clr:0x000033, alpha:50}, {x:-.75,y:4}, {cx:0, cy:4.5, x:.75,y:4}, // from -.75,4 {x:1,y:-1}, {cx:1,cy:-3,x:0,y:-4}]; // Rocket fins var finModel = [ {mx:-1,my:-1,cx:-3,cy:4,x:-2,y:6,bf:0x0000FF,bfa:80}, {cx:-1,cy:4.5,x:-.75,y:4}, {x:-1,y:-1}, {mx:.75,my:4,cx:1,cy:4.5,x:2,y:6}, {cx:3,cy:4,x:1,y:-1}, {x:.75,y:4,ef:1} ]; // Routine to scale model to arbitrary size function scaleModel(m,s) { for (var i = 0; i &lt; m.length; ++i) { var pt = m[i]; if (pt.mx != undefined) { pt.mx *= s; pt.my *= s; } if (pt.cx != undefined) { pt.cx *= s; pt.cy *= s; } pt.x *= s; pt.y *= s; } } // Draw a model // function drawModel(m) { for (var i = 0; i &lt; m.length; ++i) { var pt = m[i]; if (pt.bf != undefined) this.beginFill(pt.bf, pt.bfa); if (pt.pen != undefined) this.lineStyle(pt.pen,pt.clr,pt.alpha); if (pt.mx != undefined) this.moveTo(pt.mx,pt.my); if (pt.cx != undefined) this.curveTo(pt.cx,pt.cy,pt.x,pt.y); else if (pt.x != undefined) this.lineTo(pt.x,pt.y); if (pt.ef != undefined) this.endFill(); } } // Ship Movement and most game-play stuff happens here function ShipMove() { // Steering &amp; Thrust if (Key.isDown(Key.LEFT)) this._rotation -= 5; else if (Key.isDown(Key.RIGHT)) this._rotation += 5; if (Key.isDown(Key.CONTROL) || Key.isDown(Key.UP)) { this.vx += Math.sin(this._rotation*kDegToRad); this.vy -= Math.cos(this._rotation*kDegToRad); } else if (Key.isDown(Key.DOWN)) { this.vx *= .9; this.vy *= .9; } // Basic movement with acceleration and damping this._x += this.vx; this._y += this.vy; // Wrap around edges of stage if (this._x &lt; -this._width) this._x += SW+this._width*2; else if (this._x &gt; SW+this._width) this._x -= SW+this._width*2; if (this._y &lt; -this._height) this._y += SH+this._height*2; else if (this._y &gt; SH+this._height) this._y -= SH+this._height*2; } // Initialize new ship function NewShip() { ship_mc._x = SW/2; ship_mc._y = SH/2; ship_mc.onEnterFrame = shipMove; } // Assign a sprite model to a movieclip &amp; draw it // MovieClip.prototype.setModel = function(m) { this.model = m; this.drawModel(m); } MovieClip.prototype.drawModel = drawModel; scaleModel(fuseModel, MW*.8); // Using a slightly smaller rocket than original drawing scaleModel(finModel, MW*.8); // One Time Initialziation // _root.createEmptyMovieClip("ship_mc", 2); ship_mc.createEmptyMovieClip("fuselage", 1); ship_mc.fuselage.setModel(fuseModel); ship_mc.createEmptyMovieClip("fins", 2); ship_mc.fins.setModel(finModel); NewShip(); // } //} </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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