开发者

Remote Image with basic authentication?

开发者 https://www.devze.com 2023-03-23 00:23 出处:网络
I would like to load a an image from an external domain and I have the below so far: private function get_coverArt(coverArtID:String):void

I would like to load a an image from an external domain and I have the below so far:

            private function get_coverArt(coverArtID:String):void
        {
            var requestString:String = "/rest/getCoverArt.view?v=1.5.0&c=AirSub&id=" + coverArtID;
            var requestURL:String = subServerURL + requestString;

            myCoverArtLoader = new URLLoader();
            var myRequest:URLRequest = new URLRequest();

            var authHeader:URLRequestHeader = new URLRequestHeader();
            authHeader.name = 'Authorization';
            authHeader.value = 'Basic ' + credentials;
开发者_开发百科
            myRequest.requestHeaders.push(authHeader);
            myRequest.url = requestURL;
            myRequest.method = URLRequestMethod.GET;
            myCoverArtLoader.dataFormat = URLLoaderDataFormat.BINARY;

            myCoverArtLoader.addEventListener(Event.COMPLETE, set_coverArt);
            myCoverArtLoader.load(myRequest);   

        }

        private function set_coverArt(evt:Event) : void {
            coverArtImg = new Image();

            var loader:Loader = new Loader();
            loader.loadBytes(myCoverArtLoader.data);
            coverArtImg.source = loader;
        }

This does not seem to work - any help?

Thanks!


Try setting the source directly like so:

        private function set_coverArt(evt:Event) : void {
            coverArtImg = new Image();
            coverArtImg.source = myCoverArtLoader.data;
        }

Also, check your authentication, here's a question I answered regarding the auth :

Actionscript 3: Reading an RSS feed that requires authentication

0

精彩评论

暂无评论...
验证码 换一张
取 消