AS3: Get URL name - actionscript-3

Trying to get the current URL of the website I have posted the flash object in, without using Javscript or ExternalInterface calls.
e.g.
Website Im posting in is http://some.forum.com
Website of swf is http://uploaded.to/site/of/object.swf
In my post at some.forum.com I include in the post:
[flash=100,100]http://uploaded.to/site/of/object.swf[/flash]
Unfortunately it keeps returning the url of website I initially uploaded to, and not the current forum I am linking it in.
Current used methods are:
var urlname:LocalConnection = new LocalConnection();
trace(urlname.domain());
and
var urlName:String = this.loaderInfo.url;
trace(urlName)
Both returning uploaded.to/site/of/object.swf, and not some.forum.com
How do I get my desired result?

Not sure if it applies to your scenario but have you tried BrowerManager: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf64e50-7ff8.html
Something like
var browserManager:BrowserManager = BrowserManager.getInstance();
trace(browserManager.url);

Hmm. Well I've found a small workaround: Referrer.
All I need to do is get the swf to request another website that performs some javascript or php to return the URL of the referrer website.
var textLoader:URLLoader = new URLLoader()
var textReq:URLRequest = new URLRequest("http://my.site.com/findReferrer.html");
textLoader.load(textReq);
textLoader.addEventListener(Event.COMPLETE, trace(textLoader.data);
Unfortunately referrer is purely browser dependent and often doesn't work for https.
So back to square one..

Related

change EJS varaibles without refreshing the page Nodejs

so I have this problem, Im trying to build a website in which people can give out links which I will then analyze using request-promise.js (so on the server side) . This analysis will try to find embed videos in the given link. If present I want to make that emebed video appear in an iframe on my current page.
So for now Ive managed to get the embed the video, and render it in an EJS template variable , but this means that I have to use res.render('page', variables) and from my understanding that means reloading the page.
What I want to know is if there is a way to do that without reloading the page ?
(my goal is to make the found video appear in a bootstrap modal div that appears after people gave the link and clicked on my upload button that trigers the scrapping of the given link)
Thanks for your help
Pardon me if my question is unclear
You can use an XMLHttpRequest to get the data from the server asynchronously and display/store them on the page without reloading the whole page.
var url = '/get-embed-video/'+link;
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4) {
// here get the response from the server
// and display your data
}
}
xmlHttp.open("GET", url, true); // false for synchronous request
xmlHttp.send(null);

How to redirect to a webpage that accepts post requests?

I am working on a project where I need to scrap data in JSOUP and the show as HTML in my webpage and on clicking view more I am forwarding to the scrapped URL, issue is where GET url's are working fine but POST request for aspx are not working as it expects some __EVENTVALIDATION, etc,.. as input in form.
The webpage is kepler.sos.ca.gov, if you click on Corporation Name then enter ESCROW, then submit, some results will come up, which I am able to do in JSOUP, but unable to redirect using javascript:__doPostBack('ctl00$content_placeholder_body$SearchResults1$GridView_SearchResults_Corp','DetailCorp$0').
Please advice.
There is a answer over here : unable to get results from jsoup while giving post request
`Connection.Response response = Jsoup.connect(url)
.method(Connection.Method.GET)
.execute();
Document responseDocument = response.parse();
Map<String, String> loginCookies = response.cookies();
Element eventValidation = responseDocument.select("input[name=__EVENTVALIDATION]").first();
String validationKey = eventValidation.attr("value");
Element viewState = responseDocument.select("input[name=__VIEWSTATE]").first();
String viewStateKey = viewState.attr("value");
response = Jsoup.connect(url)
.cookies(loginCookies)
.data("__EVENTTARGET", "")
.data("__EVENTARGUMENT", "")
.data("__LASTFOCUS", "")
.data("__VIEWSTATE", viewStateKey)
.data("__VIEWSTATEENCRYPTED", "")
.data("__EVENTVALIDATION", validationKey)
.data("ctl00$content_placeholder_body$BusinessSearch1$TextBox_NameSearch", "aaa") // <- search
.data("ctl00$content_placeholder_body$BusinessSearch1$RadioButtonList_SearchType", "Corporation Name")
.data("ctl00$content_placeholder_body$BusinessSearch1$Button_Search", "Search")
.method(Connection.Method.POST)
.followRedirects(true)
.execute();
Document document = response.parse(); //search results
System.out.println(document);`
JSoup is not a browser. It does not interpret JavaScript and you can't fire a POST request through a JavaScript link.
JSoup is however quite capable doing POST requests. To use JSoup here, you need to figure out how the actual request is built by the JavaScript. You then can run the same algorithm coded in Java and create the link and do the POST request.
An easier way of achieving what you want is maybe a switch in technology. You can use selenium for example, which allows to "remote control" a real browser, which should have no problem running the JavaScript of that page.

Grabbing some specific text from the URL of the SWF file? Action Script 3.0

OK, So I have a banner that will be place on a website and depending on the url I need to update the text in the swf banner. The text I need to grab will be something like this in the URL.
product="abc"
The "abc" could be different number of characters. I don't have the exact url to work with.
I got a partial answer over here: Get Current Browser URL - ActionScript 3
However this does not explain how I can specifically only get the name of the product.
Thanks You
You can do something like this:
//check to make sure you can use ExternalInterface
if(ExternalInterface.available){
//grab the url from JavaScript
var url:String = ExternalInterface.call("window.location.href.toString");
//make sure the url is valid and has querystring parameters (eg a ?)
if(url && url.length > 0 && url.indexOf("?") > -1){
//split the url and grab everything after the ?, convert that into URL variable object
var params:URLVariables = new URLVariables(url.split("?")[1]);
trace(params.product); //abc
}
}
For more info on getting the url properly, see the answer to this question
You need a webservice or flashvars to know what the current product.
I hope this is helpful for you.
:)

Load profile image from Facebook with Actionscript 3

I'm trying to load profile images (friend images) from Facebook with AS3 but I seem to be running into a security issue.
I'm currently using the "official" Adobe Facebook API for Actionscript 3 which works fine. However, I seem to be having trouble loading profile images when running my application in a browser. The images load fine when running in the Flash IDE.
The images are being loaded from https://graph.facebook.com and there seems to be a crossdomain.xml policy on that domain:
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" secure="false" />
<site-control permitted-cross-domain-policies="master-only" />
</cross-domain-policy>
In other sources I found that adding a ContextLoader to my Loader object when loading the image should solve the problem but this doesn't seem to be the case either:
loader = new Loader();
// add some listeners here...
loader.load( new URLRequest( "imageurl" ), new LoaderContext(true) );
I'm not quite sure how to proceed at the moment. I was hoping that the Adobe Facebook API would provide assistance in this but I can't seem to find anything that solves this issue.
Any help greatly appreciated.
UPDATE:
I just noticed that when I visit one of the images in a browser that I'm actually redirected to Facebook's CDN where the actual image is stored. When I hard-code the image url with the redirected URL I can load the image in the browser. It seems that this is not a security issue after all but a redirection issue.
If this is a redirection issue then the question would become; How can I have Flash Player load an image from a redirected URL?
UPDATE 2:
It seems that the URLRequest class has a followRedirects property which is only available in AIR.
UPDATE 3:
I'm currently using a PHP script to get me the redirected URL as a work around but this of course is far from ideal and potentially a big strain on my server.
I had the same problem and it looks like you have to manually load the crossdomain file of the domain you are redirected to in actionscript. For now, it looks like all facebook profile images are finally loaded from the domain http://profile.ak.fbcdn.net/.
I just added this line before loading the images:
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
This should allow for loading the redirected images, as long as the redirect domain does not change. ;)
You can use a URLLoader and load the image as a ByteArray. This appears to work regardless of the redirect. You can then use the ByteArray as the source for an Image/BitmapImage or use a Loader to load the bytes as you would have the image url in the first place.
For example:
var urlRequest:URLRequest = new URLRequest("http://graph.facebook.com/id/picture");
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, completeHandler);
urlLoader.load(urlRequest);
function completeHandler(event:Event):void
{
var byteArray:ByteArray = loader.data;
// Then either:
bitmapImage.source = byteArray;
// or:
var loader:Loader = new Loader();
...
loader.loadBytes(byteArray);
...
}
it should be a relitively easy thing to do, all of the facebook profile images can be found by using the picture root of the graph API. like this link:
"http://graph.facebook.com/" + userid + "/picture"
I would like to confirm martin's solution here.
My case goes from testing the application on AIR platform which is fine and works great, the image loaded successfully.
But when I port it into canvas app on facebook then I face a problem, the profile images won't come along, it cannot load.
I use what martin suggest here. And if you track a url redirection, you will see that actually image profiles are located at that CDN server not facebook itself, so you need to load that domain's policy file according to actionscript's security-sandbox.
Thanks again.
totally guessing but you could use URLLoader to get the data from the redirected call, then parse it together into a picture xD
I am using two loadPolicyFile calls, as it seems there are 2 possible CDNs that facebook uses. This is working for me but of course, a generic solution is preferable, facebook might again add another CDN and things would just stop working on their own --
Security.loadPolicyFile('http://profile.ak.fbcdn.net/crossdomain.xml');
Security.loadPolicyFile('http://profile.cc.fbcdn.net/crossdomain.xml');
The URLLoader solution suggested by #Stiggler might work. I haven't tried. But it seems heavier compared to using a Loader object.
Since there are a lot of domains where Facebook stores it's photos I wrote a little script that uses the domain of the image to load the appropriate policy file:
import com.adobe.net.URI;
import flash.system.Security;
var someFacebookImageUrl:String = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/c66.66.828.828/s160x160/537210_440478782684964_233907781_n.jpg";
var uri:URI = new URI(someFacebookImageUrl);
Security.loadPolicyFile(uri.scheme + "://" + uri.authority + "/crossdomain.xml");
Nice this is that it works not only for the profile images but for all images facebook uses.
Hope this helps some of you!
PS: The URI class is part of the as3 core lib: http://code.google.com/p/as3corelib/

Get Current Browser URL - ActionScript 3

I'm trying to get current browser url. I have already tried with External Call, and it didn't work. And with loaderInfo.url I receive the current SWF url.
Give this a go:
import flash.external.ExternalInterface;
var url:String = ExternalInterface.call("window.location.href.toString");
if (url) textfield.text = url;
should do the trick.
There are a couple of ways to solve this problem, however all of them involve the use of JavaScript to query the browser directly.
My preferred way to solve this problem would be to provide the URL via a flashVar property, direct from the embed code (personally, I would reccomend using SWFObject to make this easier); don't forget you will need to URL Encode it to avoid markup issues.
var flashvars = {
browserURL: escape(location.href)
};
swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0", "expressInstall.swf", flashvars);
Now you will be able to access the Browser URL via the loaderInfo object:
trace(stage.loaderInfo.parameters["browserURL"]);
note that this will only work if you have control of generated HTML for your SWF file - if users are going to be grabbing the SWF and writing their own embed HTML, it's not going to work.
If you don't have control of the flash embed HTML, then you will need to get flash to query the browser at runtime using the ExternalInterface class; other people have suggested the use of "window.location.href.toString" however this can prove problematic in IE6, I find the following works reliably across all browsers
const browserURL : String = ExternalInterface.call("eval", "window.location.href");
Note that in order for this to work, you will need to grant JavaScript access to your Flash movie, this is done, again, via the HTML embed code and the allowScriptAccess param
var url:String = loaderInfo.loaderURL;
seems to work too.
I would try passing the required info in as a flashvar. Not the best out of the box solution I know, but it will work.
Flash: FlashVars in AS3
i think its posible to use the external interface an do it with javascript window.location
I have been using flash for a long time and never noticed this one. It only gives the domain though for security. It does work through loaded swfs as well. Not sure about iframes.
Security.pageDomain