Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-18-2009, 05:11 AM   #1
Registered User
 
Join Date: Nov 2007
Posts: 45
Default Wikimedia and BitmapData.draw()

I'm trying to use graphics from wikimedia.org to tile the background of a shape, and I just want confirmation that this is something that can't be done. I don't think there are crossdomain.xml files at wikimedia.org so my guess is that this can't be done. Here's the code:

Code:
var loader:Loader = new Loader();
var loadercontext:LoaderContext = new LoaderContext();
loadercontext.checkPolicyFile = true;
var request:URLRequest = new URLRequest("http://upload.wikimedia.org/wikipedia/en/3/39/The_Tonight_Show_with_Conan_O'Brien-Intertitle.jpg");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);
loader.load(request, loadercontext);
var shape:Shape = new Shape();
addChild(shape)

function loadHandler(evt:Event):void {
	var bitmapdata:BitmapData = new BitmapData(loader.contentLoaderInfo.width, loader.contentLoaderInfo.height, false);
	bitmapdata.draw(loader);
	shape.graphics.beginBitmapFill(bitmapdata, null, true);
	shape.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
	shape.graphics.endFill();
}
It works fine locally, of course, but not placed on my server. I doubt Security.allowDomain would make a difference (I have tried) because that's for swfs, not bitmaps.

Am I right in thinking this is a lost cause? I would appreciate any assistance.

Thanks, Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 11-18-2009, 05:56 AM   #2
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,810
Send a message via AIM to abeall
Default

Yes, I think you are right that without a crossdomain policy you won't be able to do what you want within the web sandbox. You can do it in the local-trusted or AIR sandbox I believe. You could also do it with a proxy: set up a server script at your domain to fetch the image and return it that way.
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Old 11-18-2009, 06:05 AM   #3
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

Quote:
Originally Posted by abeall View Post
You could also do it with a proxy: set up a server script at your domain to fetch the image and return it that way.
Thanks, I saw that solution mentioned elsewhere, and I'll investigate it. If anyone has tried this solution, I'd be happy to know how it worked out.

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 11-18-2009, 06:09 PM   #4
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,810
Send a message via AIM to abeall
Default

I've never done it with images before, only XML and text, but this script says it will work with images:

http://www.abdulqabiz.com/blog/archi...main-requests/
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Old 11-18-2009, 06:16 PM   #5
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

Quote:
Originally Posted by abeall View Post
I've never done it with images before, only XML and text, but this script says it will work with images:
Wow, thanks! I've found stuff on his blog related to the crossdomain security error, but I completely missed his script. I'll give this a try.

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 11-19-2009, 02:22 PM   #6
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

Well, I did give Abdul Qadiz's php proxy script a trial, but no joy. Here's how I changed the ActionScript:

Code:
var loader:Loader = new Loader();
var loadercontext:LoaderContext = new LoaderContext();
loadercontext.checkPolicyFile = false;
var urlrequest:URLRequest = new URLRequest("http://www.mydomain.com/scripts/proxy.php");
var urlvariables:URLVariables = new URLVariables();
urlvariables.url = escape("http://upload.wikimedia.org/wikipedia/en/3/39/The_Tonight_Show_with_Conan_O'Brien-Intertitle.jpg");
urlvariables.mimeType = "image/jpeg";

urlrequest.data = urlvariables;
urlrequest.method = URLRequestMethod.POST;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
loader.load(urlrequest, loadercontext);
var shape:Shape = new Shape();
addChild(shape)

function errorHandler(e:IOErrorEvent):void {
	ExternalInterface.call("window.alert", e.toString());
}

function loadHandler(evt:Event):void {
	try {
		var bitmapdata:BitmapData = new BitmapData(loader.contentLoaderInfo.width, loader.contentLoaderInfo.height, false);
		bitmapdata.draw(loader);
		shape.graphics.beginBitmapFill(bitmapdata, null, true);
		shape.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
		shape.graphics.endFill();
	} catch (e:SecurityError) {
		ExternalInterface.call("window.alert", e.toString());
	}
}
But I get back Error #2124, which basically means that Flash can't figure out what type of file has been returned to Flash.

Any ideas what I've done wrong?

Thanks,

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 11-23-2009, 08:10 PM   #7
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,810
Send a message via AIM to abeall
Default

Your AS3 code look right to me, I guess it's a PHP issue which isn't returning the data the way it should (or possibly not loading the data properly in the first place.)

My only idea on the AS3 side would be to try to load the data as binary instead and use Loader.loadBytes to convert to an image in AS. Be aware that loadBytes is basically injecting anything compatible with Loader into your SWF (including other SWFs) without any security sandbox limitations, I think.
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Old 11-23-2009, 09:51 PM   #8
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

Quote:
Originally Posted by abeall View Post
Your AS3 code look right to me, I guess it's a PHP issue which isn't returning the data the way it should (or possibly not loading the data properly in the first place.)

My only idea on the AS3 side would be to try to load the data as binary instead and use Loader.loadBytes to convert to an image in AS. Be aware that loadBytes is basically injecting anything compatible with Loader into your SWF (including other SWFs) without any security sandbox limitations, I think.
Thanks, I'll try that as a temporary solution but you're right, that's probably risk.

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:52 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.