Search code examples
cross-domainflashurlrequest

AS3 - URLRequest not working


My flash SWF needs to load "photo.jpg" using URLRequest but in vain. Heres how I am doing it

imLoader = new Loader();
imLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
imLoader.load(new URLRequest("photo.jpg"));

The SWF and photo are both located in the same directory on my localhost server. When i render it in the browser, photo doesn't load. But when i do it manually by simply opening the SWF, photo loads up properly.

Is it something related to crossdomain or what is the problem?


Solution

  • The path is relative to the HTML document. So if your image and SWF are not in the same directory as the HTML you need to provide a path (absolute or relative to the HTML).

    So if your SWF and image are in 'media' directory you would need:

    imLoader.load(new URLRequest("media/photo.jpg"));
    //or
    imLoader.load(new URLRequest("/media/photo.jpg"));
    //or (if SWF and image are on different server)
    imLoader.load(new URLRequest("http://www.domain.com/media/photo.jpg"));