Flash是如何调用存在数据库的图片路径的?

2025-05-10 16:20:07
推荐回答(3个)
回答1:

imagePath="image\\a.jpg" //注意斜杠
var img:Bitmap;
var loader:Loader=new Loader();
loader.load(imagePath);
loader.contentLoaderInfo.addEventLIstener(Event.COMPLETE,loaded);
function loaded($ev:Event):void{
loader.removeEventListener(Event.COMPLETE,loaded);

img=$ev.target.content as Bitmap;

addChild(img);

loader.unloadAndStop();

}
如果看了上面仍不清楚,推荐你看看数据库相关视频:http://edu.51cto.com/course/courseList/id-15.html

回答2:

imagePath="image\\a.jpg" //注意斜杠
var img:Bitmap;
var loader:Loader=new Loader();
loader.load(imagePath);
loader.contentLoaderInfo.addEventLIstener(Event.COMPLETE,loaded);
function loaded($ev:Event):void{
loader.removeEventListener(Event.COMPLETE,loaded);

img=$ev.target.content as Bitmap;

addChild(img);

loader.unloadAndStop();

}

回答3:

package as3.load {
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;

public class ResLoader {
private var loader:Loader;
private var url:String;
private var callBack:Function;
private var domain:ApplicationDomain;
public function ResLoader() {
this.loader = new Loader();
}

public function loadRes(url:String, callBack:Function, domain:ApplicationDomain = null):void {
this.url = url;
this.callBack = callBack;
this.domain = domain;
addEvent();
startLoad();
}

private function addEvent():void {
this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
this.loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
}

private function startLoad():void {
this.loader.load(new URLRequest(url), new LoaderContext(false, domain));
}

private function onLoadComplete(evt:Event):void {
var content:DisplayObject = loader.contentLoaderInfo.content;
callBack.apply(null, [content]);
}

private function onIoError(ioError:IOErrorEvent):void {
trace("下载"+url+"失败!");
}
}
}
package as3{
import flash.display.DisplayObject;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.system.ApplicationDomain;

import as3.load.ResLoader;
import as3.load.ResLoader;

public class LoaderTest extends Sprite {
private var btnStart:SimpleButton;
public function LoaderTest() {
btnStart = SimpleButton(this["btn_start"]);
btnStart.addEventListener(MouseEvent.CLICK, onClickStartLoad);
}

private function onClickStartLoad(evt:MouseEvent):void {
btnStart.removeEventListener(MouseEvent.CLICK, onClickStartLoad);
btnStart.visible = false;
var loader:ResLoader = new ResLoader();
loader.loadRes("img/图片1.jpg", afterGetImg, new ApplicationDomain());
}

private function afterGetImg(content:DisplayObject):void {
addChild(content);
}
}
}

文件下载有3种方式,Loader、URLLoader、URLStream,附上源码