As3 cross-origin loading of external Images

Source: Internet
Author: User

In addition to cross-origin loading, you also need to add the context parameter in the loader. Load () method. The document shows that the context parameter is the loadercontext class:

Load (request: URLRequest, Context: loadercontext = NULL): void

When loading images (JPEG, GIF, or PNG) instead of SWF files, there is no need to specify a securitydomain or an application domain, because those concepts are meaningful only for SWF files. instead, you have only one demo-to make: Do you need programmatic access to the pixels of the loaded image? If so, see the checkpolicyfile property.
Therefore, the correct syntax for cross-origin loading is:

Import flash. system. loadercontext;

VaR LC: loadercontext = new loadercontext (true );
VaR Loader: loader = new loader ();
VaR request: URLRequest = new URLRequest (URL );
Loader. Load (request, LC );

Otherwise, the Flash Player Security Sandbox reports the "checkpolicyfile" error.

This oversight was found in papervision3d. When bitmapfilematerial is used, if a cross-origin image is used for texture, although crossdomain. XML is set, a sandbox error is still reported. The solution is to modify the loadnextbitmap method:

// ___________________________________________________________________________ Load next bitmap

Private function loadnextbitmap (): void
{
// Retrieve next filename in queue
Var file: String = _ waitingbitmaps [0];

VaR request: URLRequest = new URLRequest (File );
VaR LC: loadercontext = new loadercontext (true );
VaR bitmaploader: loader = new loader ();

Bitmaploader. contentloaderinfo. addeventlistener (event. Complete, loadbitmapcompletehandler );

Try
{
// Load bitmap
Bitmaploader. Load (request, LC );

// Save original URL
_ Loaderurls [bitmaploader] = file;

// Busy loading
_ Loadingidle = false;

Papervision3d. Log ("bitmapfilematerial: loading bitmap from" + file );
}
Catch (error: Error)
{
// Remove from queue
_ Waitingbitmaps. Shift ();

// Loading finished
_ Loadingidle = true;

Papervision3d. Log ("[Error] bitmapfilematerial: Unable to Load file" + error. Message );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.