Load local SWF in AIR - actionscript-3

I want to be able to load a local SWFs in an AIR desktop application. The SWF files are located outside of the application itself on the user's hard drive.
The code I'm using is as follows:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
loader.load(new URLRequest("/Users/Oliver/Documents/sample.swf"));
The file does exist. I can test its existence using the following in Unix:
$ ls /Users/Oliver/Documents/sample.swf
However, the application is throwing the error:
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
If I attempt to load the same file from a web location (e.g. http://127.0.0.1/sample.swf), the load succeeds.
I understood that AIR could load both local and remote files. Is this not the case? Ironically, elsewhere in my application I am reading, writing and deleting arbitrary files from the local file system without issue. But I cannot load them?

I believe the issue is with your path. Try using the File class to get a path to your swf.
var f:File = File.documentsDirectory
f = f.resolvePath("sample.swf");
/* ----- */
loader.load(new URLRequest(f.url));

Related

Actionscript 3.0 Error opening URL error

I am writing an AS3 application which requires downloading xml file from external server.I am trying to connect to the external server (while testing from my local machine) to load the file however The URLLoader is unable to load it and showing "Error opening URL ". However when I put the exact url in browser, the xml file is loaded properly. The server uses https.
Following are the code/settings I am using
Security.allowDomain("*");
Security.allowInsecureDomain("*");
xmlfile = new URLLoader(new URLRequest("<fullurl>"));
The eventlistener are set properly for the loader, and have been tested locally.
I am using FlashIDE and the publish setting is set to "Access Network Only".
The server which is being connected to serves the crossdomain.xml in the root directory and contains the followings.
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" secure="true"/>
</cross-domain-policy>
I am unable to understand what is missing in my code/settings to make it work, after searching for very long time.
I have tried to connect to other server using URLRequest and it seems to be working. For example following line doesn't show the earlier mentioned error
xmlfile = new URLLoader(new URLRequest("https://www.google.com"));

AS3 AIR loading online mp3 - Error #2044: Unhandled IOErrorEvent:

UPDATE: Any version of AIR is blocking any external content. This simple pic script won't work either.
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://edvizenor.com/images/Ed-Vizenor.png"));
addChild(my_loader);
BUT HOW DO I FIX THIS?
UPDATE: More error info:
Attempting to launch and connect to Player using URL C:\Flash Apps 2014\Real Projects\Fr Letherby\Homily.swf
[SWF] C:\Flash Apps 2014\Real Projects\Fr Letherby\Homily.swf - 981 bytes after decompression
*** Security Sandbox Violation ***
Connection to http://traffic.libsyn.com/frleatherby/2015Jul18.mp3 halted - not permitted from file:///C|/Flash%20Apps%202014/Real%20Projects/Fr%20Letherby/Homily.swf
-- Untrusted local SWFs may not contact the Internet.
SecurityError: Error #2028: Local-with-filesystem SWF file file:///C|/Flash%20Apps%202014/Real%20Projects/Fr%20Letherby/Homily.swf cannot access Internet URL http://traffic.libsyn.com/frleatherby/2015Jul18.mp3.
at flash.media::Sound/_load()
at flash.media::Sound/load()
at Homily_fla::MainTimeline/frame1()[Homily_fla.MainTimeline::frame1:2]
Cannot display source code at this location.
BELOW IS THE ORIGINAL POST.
I just got a new comp using windows 8 and installed creative cloud. I am using the Flash IDE and I am trying to load a sound from online. It's a simple script but I am getting this error below.
NOTE: I am using Air 17.0 for Android. It's not working. However, when I load this same script in the flash player it works.
As you can see it's a valid live link: http://traffic.libsyn.com/frleatherby/2015Jul18.mp3
But it won't play. Did abode block this streaming feature? What simple line am I missing. This was so easy before. Is it a setting on my new computer? Thanks for any tips.
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
public class Main extends MovieClip {
public function Main() {
// constructor code
var mySound:Sound = new Sound();
mySound.load(new URLRequest("http://traffic.libsyn.com/frleatherby/2015Jul18.mp3"));
mySound.play();
}
}
}
THE ERROR
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at Main()[C:\Flash Apps 2014\Real Projects\Fr Letherby\Main.as:13]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
[UnloadSWF] Homily.swf
Test Movie terminated.
From your updates, this seems to be a security violation, and you will need to provide AIR the necessary permissions to be able to do this. Try this at the start of your application:
Security.allowDomain("Your Domain URL here");
And, In Flash IDE by going to File->Publish Settings->Flash->Local playback security and choosing either ‘Access local files only’ or ‘Access network only’.
If your application is web-based and is accessing a web-service of some kind on a different domain to the one the .swf file is hosted on you can get a sandbox violation if the domain you are accessing does not have a valid cross domain policy in place. You would also need to place a crossdomain.xml file at the root of your server which you are trying to access. It looks like this:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
<site-control permitted-cross-domain-policies="master-only"/>
</cross-domain-policy>
Hope this helps.

ActionScript 3 Error when dynamically playing audio

I am writing a game for Air iOS. I have an audio file, saved in the same directory as my .fla file. Here is the code I am using to play it:
import flash.net.URLRequest;
var snd:Sound = new Sound(new URLRequest("507560_-BlastProcess-.mp3"));
snd.play(0, 40);
This is the error I get when testing in thew Air Debug Launcher:
[SWF] Spike%20Jungle.swf - 72668 bytes after decompression
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at SpikeJungle_fla::MainTimeline/frame1()[SpikeJungle_fla.MainTimeline::frame1:128]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
[UnloadSWF] Spike%20Jungle.swf
Test Movie terminated.
How do I fix this?
Either need a cross-domain or the path to the file is incorrect.
Your AIR app is probably not running in the same folder as your mp3. See where your compiled air app is being stored and move the mp3 to that folder.
http://www.judahfrangipane.com/blog/2007/02/15/error-2032-stream-error/
You may also want to use a SoundChannel so you can stop the sound

Failed to load JSON - Sencha Touch 2

I am trying to refresh my app to show any differences in local host but the sencha CMD seems to not able to find my app.json file in the generated app folder structure. The file is deffinately there as well, but i do not know why it is tripping up with this.
Here is the log:
Sencha Cmd v4.0.2.67
[ERR] Failed to load JSON from /Users/username/Downloads/sencha/app.json - com.google.gson.stream.MalformedJsonException: Unterminated array at line 80 column 20
It seems this error only occurs when an additional css file is added in the app.json file.
Thanks.

AS3 Crossdomain imageload

Actually i have to load images into stage from any server,
so tried using crossdomain.xml from my server root.
though it throughs error
SecurityError: Error #2122: Security sandbox violation:
Loader.content: http://sss/Player.swf cannot access
http://ffff/images/logo-bg.jpg. A policy file is required, but the
checkPolicyFile flag was not set when this media was loaded. at
flash.display::Loader/get content() at
SS4UPlayer_fla::MainTimeline/ss4uLogoCompleteHandler()
Whats the problem, Please can you find it.
import flash.system.LoaderContext;
Using this LoaderContext i just got clear my problem and loaded config.xml under my root directory.