0

我想从硬盘加载图像并显示在我的 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");
        }
    }   
}
4

1 回答 1

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;
    }
}

我将“默认”块添加到 switch 块以帮助检查可能的错误。Loader 对象是一个显示对象,因此您可以像任何其他显示对象一样定位它。

于 2012-12-16T01:19:26.457 回答