How to use httpget on AdobeAIR? - actionscript-3

Using some home automation software that allows me to use httpget/httppost to get the status and control the state of devices in my home. I can use it just fine when I'm on my home wifi network (using the internal IP address in the URL), but when I attempt the same outside of my network, nothing happens. I have all ports forwarded properly, because if I post the exact same URL into my browser, it will perform whatever task was indicated.
An example would be:
function LampOn(event:MouseEvent):void{
import flash.net.*;
var url:String = "http://" + ipaddy + "/HomeSeer_REST_API.aspx?function=setdevicebyname&param1=lamp&param2=on";
var request:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
loader.load(request);
}
When I use my home IP in the variable 'ipaddy' it works fine, when I use my external IP (in the form username:password#ipaddress:port ) it does nothing.

Related

Why am I receiving a flash player security error when trying to access facebook graph api photos?

I'm using the flash debug player(version 16) and I'm trying to access a users photo from within flash as3. Firstly, the Security error i'm receiving, here it is.
SecurityError: Error #2122: Security sandbox violation: Loader.content: http s://graffiti-galore.herokuapp.com/fb/GraffitiGalore.swf?build=0001 cannot access http s://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/c46.46.570.570/s50x50/398269_10152199084495525_2139734276_n.jpg?oh=29be37fd74f7d338a7b5c23b9aadd474&oe=5548F552&gda=1431395518_d142c304e8b8afa8df340e6cac093b29. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
at flash.display::Loader/get content()
at PictureBox/onCompleteLoadingImage()
I'm using the free Heroku dino that is being offered and I'm simply doing a fetch call to the graph api users object. fetching the id,first_name, last_name,picture.
The picture url comes back as hosted on https facebook servers.
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/c46.46.570.570/s50x50/398269_10152199084495525_2139734276_n.jpg?oh=29be37fd74f7d338a7b5c23b9aadd474&oe=5548F552&gda=1431395518_d142c304e8b8afa8df340e6cac093b29
Links like the one above. For some reason i'm receiving this Security error whenever loading up the image from my flash as3 facebook app.
Below is the code i'm using to fetch the image.
[code]
public function setupPhoto(url:String):void
{
removeAllChildren();
var urlRequest1:URLRequest = new URLRequest(url);
this.loader1 = new Loader();
this.loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteLoadingImage);
this.loader1.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onErrorLoadingImage);
this.loader1.load(urlRequest1);
//imageLoader = new ImageLoader(url);
//imageLoader.addEventListener(Event.COMPLETE, onCompleteLoadingImage);
//imageLoader.load();
}
private function onErrorLoadingImage(e:IOErrorEvent):void
{
debugPanel.writeLine("ERROR LOADING IMAGE!!!");
debugPanel.writeLine(e.text);
}
public function onCompleteLoadingImage(e:Event):void
{
//var sprite:Sprite = this.loader1.content as Sprite;
//updatePicture(sprite);
updatePicture1(this.loader1.content);
}
[/code]
this works for me with Facebook:
var lc:LoaderContext = new LoaderContext(true, null, null);
// now add the LoaderContext to your loader
this.loader1.load(urlRequest1, lc);
you don't have to create a LoaderContext every time, just create it once and use everywhere.

Passing URL Params to new browser window/tab on USB drive from Flash moviclip

I'm running a website from a USB drive and trying to pass parameters through the address bar to a new window when a button is clicked in the embedded flash swf.
The problem is that on some workstations the parameters are stripped from the URL. On others it works fine.
I have a movieclip button that when clicked calls this function:
function onReleaseHandler(myEvent:MouseEvent) {
var printURL = "html/certPopup.html";
var request:URLRequest = new URLRequest(printURL);
var variables:URLVariables = new URLVariables();
variables.vModTitle = modTitle;
variables.vFirstName = firstName;
variables.vLastName = lastName;
variables.vLang = language;
request.data = variables;
navigateToURL(request, "_self");
}
On machines where this is working, the certPopup.html page opens in a new tab and the URL in the address bar looks like this:
file:///G:/courses/flash/1/EN/course/html/certPopup.html?vFirstName=Charlie&vModTitle=This%20is%20the%20Title&vLang=EN&vLastName=Brown
On workstations where this is not working the URL in the address bar appears as:
G:\courses\flash\1\EN\course\html\certPopup.html
Browser is IE version 10.0.9200.16540 on all workstations.
Flash version is WIN 11,6,602,180 or higher.
I'm really stumped as to why the URL in the address bar is different on different machines, with the parameters being stripped.
The reason the first works and second doesn't is, that the first one is a URL, the second one is a file path. I have no idea if this might work, but try changing
var printURL = "html/certPopup.html";
to
var printURL = root.loaderInfo.loaderURL.replace(root.loaderInfo.loaderURL.split("/").pop(), ""); + "html/certPopup.html";
But since you are working on an offline project: Why donĀ“t you work with AIR with captive runtime? Would be easier and the possibilities would be much greater?

AS3 using the loader CLASS with .content

I've been working on a program, but currently I'm stuck.
My problem is the .content statement in my script. Since I'm loading a PNG from the web I have the Local playback security set to "Access network only". When I load pictures locally (of course with settings at "Access local files only", and local URLRequests) the program works just fine, but when loading from the web the .content makes my program stop, I've found this out with lots of testing. It seems the .content only works when the SWF file only uses local requests, is this correct?
I know that I can use addChild(loader), but I need to get the PNG file out of the loader so that I can turn it into a bitmap and edit it. Any ideas? The script is below.
var loader:Loader = new Loader;
var ar:Array = [];
var teller:Number = 0;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, paste);
knapp.addEventListener(MouseEvent.CLICK, neste);
function paste(evt) {
ar[teller] = loader.content;
ar[teller].x = ar[teller].width*teller;
addChild(ar[teller]);
}
function neste(evt) {
teller ++
loader.load( new URLRequest ("http://www.minecraft.net/skin/Notch.png"));
}
loader.load( new URLRequest ("http://www.minecraft.net/skin/Notch.png"));
Cross-domain policies prohibits image data manipulation for images loaded from another domain than the one the swf file is loaded from:
http://www.dwuser.com/flashslideshow/v4/help/advanced_topics/understanding_flash_player_cross_domain_loading_restrictions.html

Connect to IP in application layer, Adobe Air

I'm working on a project about "controlling embedded system by smartphones via wifi",
I developed my app on adobe Air, and built my system on PIC microcontroller to accept connections on application layer (Http), the ip address is 192.168.20.60:80(responsed when browsing from web browsers).
Instead of using sockets to connect through port 80, I used urlloader to read HTML pages (urlrequest("x.com")).
But when I tried to connect to ip address IOexception appears,
here's the code:
var PicPage:URLLoader=new URLLoader();
PicPage.load(new URLRequest("192.168.20.60")); //worked using DNS
lgn.addEventListener(Event.COMPLETE,ff);
function ff(e:Event):void{
var s:String=e.target.data;
trace(s);
}
As Pixel Elephant said, You need to have http:// in front of the IP you are trying to contact. You don't need to specify port 80 though.
Try the following code:
var PicPage:URLLoader = new URLLoader();
PicPage.addEventListener(Event.COMPLETE, onLoaded);
PicPage.addEventListener(IOErrorEvent.IO_ERROR, onError);
PicPage.load(new URLRequest("http://192.168.20.60/"));
protected function onLoaded(e:Event):void {
var s:String = e.target.data;
trace(s)
}
protected function onError(e:Event):void {
// Handle the error in any way you'd like
}
I've used this code ( and variations of it ) multiple times myself and it has served me well.

Foursquare API request not working once deployed, crossdomain issues?

I threw together a simple app in flash ide / as3 that pulls photos from a foursquare location. It works locally but once deployed on the web it does not work. I would guess it's a crossdomain issue but what I've found online (link below) so far doesn't answer my question.
http://groups.google.com/group/foursquare-api/browse_thread/thread/ab963f74fde8ae9f/3e68559966acf7c9
I've checked the local vs network setting.I've read I shouldn't need a crossdomain file on my server.
And I believe I've read that I shouldn't need a php proxy for foursquare like I need with twitter...
Not sure what else it can be.
the box where it says testing should trace the response but it never fills, it's like the call stops dead in its tracks after it hits the crossdomain file on foursquare and I don't even get an error response. http://physicalgraffitea.com/wp-content/swf/Foursquare-e.swf
Distilled the AS3 down to it's leanest here, sans the ID and Secret.
Any help? Thanks
Security.allowDomain("http://www.foursquare.com");
Security.loadPolicyFile("http://api.foursquare.com/crossdomain.xml");
import flash.net.URLRequest;
import flash.net.URLLoader;
import com.adobe.serialization.json.JSON;
var resource = "https://api.foursquare.com/v2/venues/4b7071c8f964a520d51a2de3/photos?group=venue&limit=6&client_id="+myId+"&client_secret="+mySecret+"&v=20120517";
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(resource);
request.method = URLRequestMethod.GET;
loader.addEventListener(Event.COMPLETE, onComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
loader.load(request);
function onComplete(e:Event):void {
var loader:URLLoader = URLLoader(e.target);
outputtxt.text = loader.data;
trace(loader.data);
var jsonData:Object = JSON.decode(loader.data)
}
function onIOError(e:Event):void {
var loader:URLLoader = URLLoader(e.target);
outputtxt.text = "error " + loader.data;
}
After a lot of fussing around the only way I could get it to work is to yes, use a crossdomain proxy php file with the foursquare api.
But that alone didn't solve my problem the swf needed to be referenced with the full http path but without the "www" in the path. "http://mydomain.com/swf/file.swf"
Not sure why but if you have similar cross domain issues try removing the www too