我想从硬盘加载图片并在我的flash影片中显示我有点代码当我点击按钮它打开超链接所以任何人都知道图像加载功能
package{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
public class Main extends Sprite{
public function Main():void{
z_cst.addEventListener(MouseEvent.CLICK,buttonClick);
z_kp.addEventListener(MouseEvent.CLICK,buttonClick);
z_kr.addEventListener(MouseEvent.CLICK,buttonClick);
z_ka.addEventListener(MouseEvent.CLICK,buttonClick);
z_rs.addEventListener(MouseEvent.CLICK,buttonClick);
z_c.addEventListener(MouseEvent.CLICK,buttonClick);
z_vp.addEventListener(MouseEvent.CLICK,buttonClick);
z_cr.addEventListener(MouseEvent.CLICK,buttonClick);
z_cs.addEventListener(MouseEvent.CLICK,buttonClick);
}
private function buttonClick(e:MouseEvent):void{
var url:URLRequest=new URLRequest();
switch(e.target.name){
case "z_cst": url.url="http://www.star.com"; break;
case "z_kp": url.url="http://www.star.com"; break;
case "z_kr": url.url="http://www.star.com"; break;
case "z_ka": url.url="http://www.star.com"; break;
case "z_rs": url.url="http://www.gear.com"; break;
case "z_c": url.url="http://www.apple.com"; break;
case "z_vp": url.url="http://www.images.com"; break;
case "z_cr": url.url="http://www.buy.com"; break;
case "z_cs": url.url="http://www.contact.com"; break;
}
navigateToURL(url,"_blank");
}
}
}
答案 0 :(得分:0)
查看Loader {}类以加载图片 - http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html
从你的评论中,看起来你会得到它。您缺少的是您需要调用Loader对象的load()方法并将URLRequest对象传递给它。以下是一些代码,可以按照您之前的代码松散地执行此操作:
private function buttonClick(e:MouseEvent):void {
var loader:Loader = new Loader();
this.addChild(loader);
switch(e.target.name) {
case "z_cst":
loader.load(new URLRequest("/data/1.jpg"));
break;
case "z_kp":
loader.load(new URLRequest("/data/2.jpg"));
break;
case "z_kr":
loader.load(new URLRequest("/data/3.jpg"));
break;
default:
trace("buttonClick() - No matching name found");
this.removeChild(loader); // remove the Loader object from the stage as it is 'empty'
break;
}
}
我在交换机块中添加了“默认”块,以帮助检查可能的错误。 Loader对象是一个显示对象,因此您可以像任何其他显示对象一样定位它。