image.as
来自「as30的详细例子,包含了大量的例子,是不可多得的学习AS3的好资料」· AS 代码 · 共 66 行
AS
66 行
package com.example.programmingas3.asciiArt
{
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.EventDispatcher;
import com.example.programmingas3.asciiArt.AsciiArtBuilder;
/**
* Represents a loadable image and metadata about that image.
*/
public class Image extends EventDispatcher
{
// ------- Private vars -------
private var _loader:Loader;
//
// ------- Constructor -------
//
public function Image(imageInfo:ImageInfo)
{
this.info = imageInfo;
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
}
// ------- Public Properties -------
public var info:ImageInfo;
// ------- Public Methods -------
public function getBitmapData():BitmapData
{
return Bitmap(_loader.content).bitmapData;
}
/**
* Loads the image file associated with this instance.
*/
public function load():void
{
var request:URLRequest = new URLRequest(AsciiArtBuilder.IMAGE_PATH + info.fileName);
_loader.load(request);
}
// ------- Event Handling -------
/**
* Called when the image associated with this instance has completely loaded. In essence
* it passes the event along to any listeners which have subscribed with this instance.
*/
private function completeHandler(event:Event):void
{
dispatchEvent(event);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?