问题
Im loading JSON in a flashbuilder 4.5 mobile app Im working on, so far all the variables render fine and I am using left and right swipe gestures to allow the user to move through the array of items - using actionscript3.
Now I get to the part where Im working on adding an image to the stage that has its SOURCE parameter bound to a variable (thisimg2) whose value is the json value for the image url... an example of the URL is:
http://i.ebayimg.com/00/s/MTA2MlgxNjAw/%24T2eC16JHJG%21E9nm3pkoZBQDVSKHsow%7E%7E60_1.JPG?set_id=880000500F
and
http://i.ebayimg.com/00/s/MTIwMFgxNjAw/%24%28KGrHqV,%21pcE9eMM4r4ZBPmiD+Ft%21%21%7E%7E60_1.JPG?set_id=880000500F
a small percentage of the json URL values come back as really simple image URLs with no hex values and those show up just fine, but the majority of the, that appear like the 2 examples above, dont render at all and just result in the broken image/question mark symbol in flex (using desktop debug / emulator). I tried decode on the url string but that didnt work.
when I put the urls in my browsers they work fine and render in browser.
is there anything I can do to the URL's to get them work?
回答1:
Can you provide an example of a URL that is working for you?
I believe Ebay is specifically preventing Flash apps from other domains from using their images.
The URL encoding is not the problem ... Flash just relies on the browser to download them. However, take a look at this code buried deep inside the BitmapImage
component (which is the underlying thing that the Spark Image
component uses):
BitmapImage::loadExternal() (line 1513)
try
{
loaderContext.checkPolicyFile = true;
var urlRequest:URLRequest = source is URLRequest ?
source as URLRequest : new URLRequest(source as String);
loader.load(urlRequest, loaderContext);
}
Here it is telling the Loader
that it will use to fetch the image to check the source domain's crossdomain.xml file. Here is a link to that crossdomain.xml file.
Their crossdomain.xml file is specifically allowing Flash apps from various ebay domains to access the content on i.ebayimage.com. I just scanned it, but I don't see anything there allowing a wildcard (allow-access-from domain="*"
) so that non-ebay domains are permitted. So you will never be able to use those images in a Flash app, unless ebay allows you to.
[Edit]
Before you do one of the things below, you should probably determine the legality of what you're doing.
Actually, I take that back. You will never be able to use the Flex Image
or BitmapImage
components to load these images because those components check the policy file. However, you have a few options:
- extend the
BitmapImage
class and override theloadExternal()
method so it doesn't check the policy file - Use your own
Loader
to show the images. This is a bit more work inside of a Flex app, but it works (I just tested it w/a simple AS3 app).
Here's the very rudimentary AS3 application I tested with (not using Flex):
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
public class As3Project extends Sprite
{
private var loader:Loader;
function As3Project()
{
loader=new Loader();
var url:URLRequest = new URLRequest("http://i.ebayimg.com/00/s/MTA2MlgxNjAw/%24T2eC16JHJG%21E9nm3pkoZBQDVSKHsow%7E%7E60_1.JPG?set_id=880000500F");
loader.load(url);
addChild(loader);
}
}
}
来源:https://stackoverflow.com/questions/15176661/how-do-i-get-this-image-url-to-display-in-flashbuilder-4-5-using-bindable-and-a