// Copyright (C) 2007 Ian Langworth // // MovieClip creation style described here: http://osflash.org/flashcoders/as2 class Application extends MovieClip { // Needed for MovieClip to be instantiated easily static var symbolName = '__Packages.Application'; static var symbolLinked = Object.registerClass(Application.symbolName, Application) // Instance variables private var blobs; // Object constructor function Application() { super(); } // Object initialization function init(parent) { // Minimize the popup menu and add a link to my site. var appMenu = new ContextMenu(); appMenu.hideBuiltInItems(); var linkItem = new ContextMenuItem("Go to Ian's home page", function () { getURL('http://langworth.com/', '_top') }); appMenu.customItems.push(linkItem); _root.menu = appMenu; // Resizing the app adds pixels instead of scaling the graphics. Stage.scaleMode = 'noScale'; // Make sure that the origin is where we expect it to be. Stage.align = 'TL'; // Process our parameters from the tag var numBlobs = 10; if (_level0.numBlobs != null && _level0.numBlobs != '') { numBlobs = parseInt(_level0.numBlobs); } var blobColor = 0x00FF00; if (_level0.blobColor != null && _level0.blobColor != '') { blobColor = parseInt('0x' + _level0.blobColor); } var backgroundColor = 0x333333; if (_level0.backgroundColor != null && _level0.backgroundColor != '') { backgroundColor = parseInt('0x' + _level0.backgroundColor); } // Draw a color background, and do that if the window is ever resized // (which you can do in the standalone Flash player). // // NOTE: Context scope is broken in ActionScript. There's a cleaner way // of doing this called mx.util.Delegate, but I don't want to rely on // any commercial code. var self = this; var drawBackground = function() { self.beginFill(backgroundColor); self.lineStyle(0); self.moveTo(0, 0); self.lineTo(Stage.width, 0); self.lineTo(Stage.width, Stage.height); self.lineTo(0, Stage.height); self.endFill(); }; var resizeListener = new Object(); resizeListener.onResize = drawBackground; Stage.addListener(resizeListener); drawBackground(); // Create the blobs this.blobs = new Array(); for (var i = 0; i < numBlobs; i++) { var blob = Blob.create(this, this.getNextHighestDepth(), blobColor, Math.floor(Math.random() * Stage.width), Math.floor(Math.random() * Stage.height), Math.floor(Math.random() * 10) + 5); this.blobs.push(blob); } // Having every object use the stock onEnterFrame listener might imply // that each MovieClip might have its own frame rate. I want to use the // main frame rate as the clock, so I'll have everything provide an // update() method and cascade the event from that. this.onEnterFrame = this.update; } // Update a frame of the animation function update() { for (var i = this.blobs.length - 1; i >= 0; i--) this.blobs[i].update(); } // Main method which creates an instance of its own class. static function main(parent) { var app:Application = Application( _root.attachMovie(Application.symbolName, 'Application', _root.getNextHighestDepth())); app.init(parent); } }