0

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!

Omar Mir
  • 1,500
  • 1
  • 19
  • 39
  • If you want to load an image from an external domain, then why are you passing a local url? Can you also give more details about the server side, as it seems that it expects an authentication header but the format is not described in your question. Can you also add event listeners for i/o errors so that it's clear what goes wrong? – MonkeyCoder Jul 24 '11 at 09:35
  • I am not passing a local url, the first part of the url is subserverurl which is htttp://serveraddress.com and then /rest/..... gets tacked on. The server's api is rest complaint, and runs subsonic. I could avoid the issue all together by passing the credentials in the url but that seems like a bad idea. It unfortunately doesn't throw any errors during my debug. – Omar Mir Jul 24 '11 at 19:50

1 Answers1

1

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

Community
  • 1
  • 1
Nate
  • 2,881
  • 1
  • 14
  • 14