package com.exanimo.containers { import flash.display.DisplayObject; import flash.display.Sprite; import flash.net.URLRequest; import flash.system.LoaderContext; import flash.events.Event; import flash.display.Loader; /** * * The ResizePane scales display objects and JPEG, GIF, and PNG files, as * well as SWF files, to fit within its boundaries. * * @langversion ActionScript 3 * @playerversion Flash 9.0.0 * * @author Matthew Tretter * @since 2008.02.04 * */ public class ResizePane extends Sprite { private var _content:DisplayObject; private var _initialWidth:Number; private var _initialHeight:Number; /** * * Creates a new ResizePane instance. * */ public function ResizePane() { this._initialWidth = this.width; this._initialHeight = this.height; } // TODO: Add width/height accessors. until then, this is only useful when created in the ide. // // accessors // /** * * Gets a reference to the content loaded into the resize pane. * */ public function get content():DisplayObject { return this._content; } /** * * Gets or sets an absolute or relative URL that identifies the * location of the SWF or image file to load, the class name of a movie * clip in the library, a reference to a display object, or a instance * name of a movie clip on the same level as the component. * * Valid image file formats include GIF, PNG, and JPEG. To load an * asset by using a URLRequest object, use the load() method. * * @default null * */ public function set source(source:Object):void { var content:DisplayObject; // TODO: Copy support for urls, etc. from ScrollPane if (!(content = source as DisplayObject)) throw new ArgumentError('ResizePane.source can only be set to a DisplayObject (currently).'); if (this._content && (this._content.parent == this)) this.removeChild(this._content); // TODO: Add support for other loadables? if ((source is Loader) && ((source.contentLoaderInfo.bytesLoaded == 0) || (source.contentLoaderInfo.bytesLoaded != source.contentLoaderInfo.bytesTotal))) source.contentLoaderInfo.addEventListener(Event.COMPLETE, this._update, false, 0, true); this.addChild(content); this._content = content; this.update(); } // // public methods // /** * * The request parameter of this method accepts only a URLRequest * object whose source property contains a string, a * class, or a URLRequest object. By default, the LoaderContext object * uses the current domain as the application domain. To specify a * different application domain value, to check a policy file, or to * change the security domain, initialize a new LoaderContext object * and pass it to this method. * * @param request * The URLRequest object to use to load an image into the scroll pane. * */ public function load(request:URLRequest, context:LoaderContext = null):void { // TODO: Implement this method! throw new Error('The ResizePane.load() method is not yet implemented.'); } /** * * Updates the appearance of the ResizePane by rescaling the content. * This is useful if the contents of the pane change during run time. * */ public function update():void { if (content != null) { this.content.scaleX = this.content.scaleY = 1; var scale:Number = Math.min(this._initialWidth / this.content.width, this._initialHeight / this.content.height); this.content.scaleX = this.content.scaleY = scale; this.content.x = (this._initialWidth - this.content.width) / 2; this.content.y = (this._initialHeight - this.content.height) / 2; } } // // private methods // /** * */ private function _update(event:Event):void { this.update(); } } }