I have an application that is running on portal VK com. I need to load images (.png) from their domain (which are players avatars basicly). What I get is SecurityError: Error #2123. It looks like in crossdomain.xml file on their domain there is no proper tag.
I've done following things:
Set allowSecurityDomain to * in my swf
I'm passing LoaderContext to Loader::load method defined like this:
var context:LoaderContext = new LoaderContext();
var context.checkPolicyFile = true;
loader.load(new URLRequest(img), context);
This is working on other portals (facebook, mojmir, odnoklassiniki, etc..) but not this one.
If you want to load images you can use the Image tag:
<mx:Image source="http://...." autoload="true" />
You won't have to deal with cross domain policy.
In AScript you can use:
var img:Image = new Image();
img.autoLoad = true;
img.source = "http://someurl/img.png"
img.addEventListener(Event.COMPLETE, function(e:Event):void {
//loaded
});
img.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void {
//not loaded
});
Related
I need to run a swf inside an Extendscript (java) window in Photoshop. The Extendscript part pops up a Folder Selection dialog and lets user to select a folder. Then it sends the Folder path and the list of the .mp3 files in that folder to the swf file.
The swf can load and play the song
But it can't get the id3 information
The swf is in "Access Network Files Only" mode
I'm pretty sure it is a security issue and wonder if anyone knows of a workaround. Here is my code...
Thanks in advance.
var mp3FileList;
var folder;
var songList;
var songsArray:Array = new Array();
var mp3Array:Array = new Array();
if (ExternalInterface.available) {
ExternalInterface.addCallback("transferSongList", transferSongList);
}
//Extendscript opens a Select Folder dialog
//and sends the folder path and the list of .mp3 files inside the selected folder to this swf
function transferSongList(folder, mp3FileList){
songList=quickReplace(mp3FileList, "%20", " ");
songsArray = songList.split(",");
var mp3File:Sound = new Sound();
mp3File.load(new URLRequest(folder+"/" + songsArray[0]));
mp3File.addEventListener(Event.COMPLETE, parseSound(mp3File));
}
function parseSound(mp3):Function{
return function(e:Event):void {
//IF I REMOVE THE NEXT LINE THE SONG PLAYS
alertbox.text=mp3.id3.songName
mp3.play();
};
}
function quickReplace(source:String, oldString:String, newString:String):String
{
return source.split(oldString).join(newString);
}
When the user try to download the file ,i need to open a new html window and download the file , currently iam using "ExternalInterface.call" but i need to set the "requestmethod" otherwise server is throwing the error ,how to specify "requestmethod"?
Why not use the global navigateToURL method? You can pass in a URLRequest object which has a property called method and will solve your problem.
So you need something like this:
var request:URLRequest = new URLRequest("http://example.com");
request.method = URLRequestMethod.POST; // or anything you want
// parameters can be added to a URLVariables object
// which then can be set as requests data property
// example:
var params:URLVariables = new URLVariables();
params.username = "test";
params.password = "123";
request.data = params;
// load the page
// specify '_blank' parameter to open it in a new browser window
navigateToURL(request, "_blank");
This simple login form works within the test environment of CS6 (Flash 11.4) but upon exporting does not work. I've narrowed down the issue to the actual URLRequest not working properly. Hopefully somebody can shed some light!
Many thanks, Nick :)
AS3
login.loginSubmit.addEventListener(MouseEvent.CLICK, function(){
if(login.loginPassword.text!="Password" && login.loginPassword.text!=""){
login.loginSubmit.enabled = false;
// Begin URL setup for login
var loginVariables:URLVariables = new URLVariables("email="+login.loginEmail.text+"&password="+login.loginPassword.text);
var loginRequest:URLRequest = new URLRequest();
loginRequest.url = "login.php";
loginRequest.method = URLRequestMethod.POST;
loginRequest.data = loginVariables;
var loginLoader:URLLoader = new URLLoader();
loginLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
loginLoader.addEventListener(Event.COMPLETE, loginHandler);
function loginHandler(event:Event):void {
if(loginLoader.data.passed=="true"){
var hideInitial:Tween = new Tween(uiInitial, "x", Strong.easeOut, 6, -315, 0.5, true);
hideInitial.addEventListener(TweenEvent.MOTION_FINISH, function(){
member.data.email = loginLoader.data.email;
member.data.fname = loginLoader.data.fname;
member.data.lname = loginLoader.data.lname;
member.flush();
});
}else{
trace("error");
}
}
// Send PHP/SQL request
loginLoader.load(loginRequest);
}
});
You need to enable the network access for your published SWF. Go to Publish Settings for Flash (.swf) and Set the "Local playback security" settings to "Access Network Only".
Turns out that there is both a local and external URLRequest, causing trouble with the settings. I've made both the same (external) and of course hosted them on the same domain as the Flash, now works.
I am trying to upload file to server with the FileReference class.
the file is mp3 that was encoded in runtime without saving him on the local hard drive.
Is it possible to fit in the mp3Encoder into the FileReference somehow?
Thanks
Assuming you have the mp3 as a ByteArray (not sure how else it would exist at runtime if you haven't saved it to disk), you can use the URLLoader class, like this:
var scriptRequest:URLRequest = new URLRequest("PATH_TO_YOUR_UPLOAD_SCRIPT");
var scriptLoader:URLLoader = new URLLoader();
var scriptVars:URLVariables = new URLVariables();
scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
scriptVars.var1 = MP3_AS_BYTE_ARRAY;
scriptRequest.method = URLRequestMethod.POST;
scriptRequest.data = scriptVars;
scriptLoader.load(scriptRequest);
function handleLoadSuccessful($evt:Event):void
{
trace("Message sent.");
}
function handleLoadError($evt:IOErrorEvent):void
{
trace("Message failed.");
}
Then on the server, you just need to save the stream to a file and give it the correct mp3 mime type.
There's a decent tutorial, from which this example is adapted, here: http://evolve.reintroducing.com/2008/01/27/as2-to-as3/as2-%E2%86%92-as3-loadvars-as3-equivalent/
And if you need to send your request as multipart/form-data (so it appears to be an attached file), there's a good example of this here: http://marstonstudio.com/2007/10/19/how-to-take-a-snapshot-of-a-flash-movie-and-automatically-upload-the-jpg-to-a-server-in-three-easy-steps/
I am trying to upload a file to the server. I'm doing it like this:
var fileRef:FileReference = new FileReference();
fileRef.addEventListener(flash.events.Event.SELECT, selectHandler);
fileRef.addEventListener(flash.events.Event.COMPLETE, completeHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS, normalprogressHandler);
fileRef.browse();
function selectHandler(event:flash.events.Event):void
{
var params:URLVariables = new URLVariables();
params.date = new Date();
params.ssid = "94103-1394-2345";
var request:URLRequest = new URLRequest("http://www.test.com/Uploads");
request.method = URLRequestMethod.POST;
request.data = params;
fileRef.upload(request, "Custom1");
}
function completeHandler(event:flash.events.Event):void
{
trace("uploaded");
}
function normalprogressHandler(event:ProgressEvent):void
{
var percent:Number = Math.floor((event.bytesLoaded * 100)/ event.bytesTotal );
trace(percent+"%");
}
Would it be possible to upload a file but without browsig for it? I want to decide myself what file to upload instead of the user performing a browse first
You can't do that with FileReference which has the following limitations (reference):
The load() and save() APIs can only be called in response to user
interaction (such as a button click).
The locations of the loaded and save files are not exposed to
ActionScript.
The APIs are asynchronous (non-blocking).
Clearly, it would represent a major security risk if the Flash player was arbitrarily allowed to upload anything from your local file system to a remote server.
If you're trying to upload from an AIR app, you can do what you're trying to do with the File class.