Flex Image Source Server Side Flash and Air - apache-flex

I'm trying to run my flex application in the air runtime instead of flash runtime. It seems to work perfectly except the images. Adobe Air runtime tries to load them. Is there a way to change the root adresses for Image to server side? If possible I'd like to use the same code for flash runtime and air runtime .. "single codebase ;-)"
var icon:Image = new Image();
icon.source = "images/test.png";
regards
cyrill

Typically I would simply package the assets into the AIR app. That way the relative paths would be valid both in the web app and the desktop app. However, since you pointed out in the comments that we're talking 10000 images you'll have to find another solution.
What you need is a variable that is configurable for each type of project. The final code to access your images should look like:
var icon:Image = new Image();
icon.source = rootUrl + "/images/test.png";
That rootUrl may be "" for the web app, and "http://www.mydomain.com" for the desktop app. Or it could be the absolute path in both cases. It doesn't matter: we don't want to hardcode that URL into our application.
Create a .properties file (or XML, or JSON; whatever configuration file you like) that contains the value for rootUrl and read that into your application model. This configuration file can be packaged into the AIR app.
A .properties file will look like this:
#myapp.properties
rootUrl=http://www.mydomain.com
For reading the file, you could use AIR's file streaming capabilities, but I suggest you load it the old-fashioned way with a URLLoader: this way it'll work both in the web and the desktop app.

Related

ASP.NET Sound Resource not publishing

So I created an ASP.NET 4 application in VS2010, that needs to play sound to the end user, and it is working perfectly in my local development environment. The problem is the sound resource nor the Resources.resx is not being published to the server. Any idea why?
What I did:
1) Under Project  Properties  Recources I added my sound resource called: soundbyte (containing soundbyte.wav). I noticed this creates a Resource folder with the wav file and under my project a Resources.resx file referencing the file
2) In my code I play the file as follows:
Dim audioFile = My.Resources. soundbyte
Dim player = New Media.SoundPlayer(audioFile)
player.Load()
player.Play()
In the Visual Studio Solution Explorer right-click on Resources.resx and select Properties. Build Action. Set to content.
EDIT: The following resource might also help.
http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx
Ultimately, I found a way to play the sound to the client browser (as opposed to the server the asp app is running on) was to follow the techniques in this example: http://www.vbdotnetheaven.com/UploadFile/scottlysle/PlaySoundsInASPX09032006083212AM/PlaySoundsInASPX.aspx
But I found an even better way in my case was to use Javascript, which doesnt' require the Resources technique.
simply embed the sound on the page after the tag:
<embed src="Sounds/jump.wav" autostart=false width=1 height=1 id="sound1" enablejavascript="true">
Then in javascript setup the function:
function EvalSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.Play();
}
Finally play the sound in the browser as needed in Javascript:
EvalSound('sound1');

loadMovieNum in AS2/1 files loaded into an Air-based AS3 / Flex application

I am working with a very large number of legacy SWFs written in AS1 and AS2. These SWFs use loadMovieNum extensively.
I am trying to integrate these into a new Air-based app (written in either AS3 or Flex). However, loadMovieNum doesn't seem to work within the Air app.
For example, an AS2 SWF (file1.swf) may try to load another AS2 SWF using:
loadMovieNum("http://127.0.0.1/file2.swf", 5);
This works fine if the SWF is played indepedently but if it is played from within the Air app, it fails.
EDIT: What happens in the Air app is that file1.swf will load successfully but silently fails to load file2.swf. There are no errors and no exceptions. A try...catch around the loadMovieNum reports nothing and file1.swf continues to play.
The relevent code from the Air app is as follows:
AS3 version:
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("http://127.0.0.1/file1.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.load(mRequest, loaderContext);
function onCompleteHandler(loadEvent:Event):void
{
// Add to the stage
addChild(mLoader.content.parent);
}
Flex version:
<mx:SWFLoader id="swfObj" source="http://127.0.0.1/file1.swf" />
It is simply the case that loadMovieNum will not work in Air? Or is there something that can be done. Obviously, making extensive changes to the legacy SWFs is, in all liklihood, not possible.
Thanks in advance.
I've concluded that _levels are not supported in SWFs that are loaded directly into Air apps. For example, even _level0 (which should always be defined) returns as undefined. Consequently, it would appear very unlikely that loadMovieNum would be supported.
I have discovered a workaround, though. Using the HTML browser component in Air, a webpage - in which the AS2/1 SWFs are embedded - can be loaded into the Air app. If you do this then loadMovieNum works as expected in the AS2/1 files.
AS3 version:
var hLoader:HTMLLoader = new HTMLLoader();
addChild(hLoader);
hLoader.width = stage.stageWidth;
hLoader.height = stage.stageHeight;
hLoader.load(new URLRequest("file1.html"));
Flex version:
<mx:HTML id="minibrowser" width="100%" height="100%" location="file1.html" />
Unfortunately, the HTML component is not supported by all Air profiles. In particular, in my case, it is not supported by the TV profile.
Although it may not seem intuitive, this seems like a security issue. When AS2 content loads up other AS2 content, they have to be in the same security sandbox in order for them to run.
I created a quick sample just to test this theory and I was right. The reason it works in Flash is because the AS2 content is in the same sandbox as the content it is loading. But AIR security is different. So when you load up the AS2 content in AIR (using the logic you supplied), the loader gets put in the application sandbox. The sandbox is now different than the content it is loading, so it refuses to load them.
This explains why it works when using an HTML wrapper. When the HTML loads up the swf, it probably gets put in the local-with-network sandbox which is the same as the content.
So... How do you fix it?
You can try to load your content up in a different security sandbox. But really the problem is that AS3 security isn't playing nice with the AS2 security. My suggestion would be to create the AIR application without an AS3 wrapper. You can't do this directly in the tooling, but you should be able to use the ADT packager to do it. In the xml descriptor, make the initial content the AS2 swf, and package it together. Now when you launch your AIR application it uses the AS2 swf as the main application. Suddenly your files should all be in the same security sandbox, and Flash won't prevent any of the content from running.
You can test this locally by using ADL to launch the app instead of launching it directly from Flash Professional or Flash Builder. (They both use ADL, but if you call it directly you have more control over the arguments used.)
EDIT: Apparently you can't have an AS2 swf as the main swf for Desktop AIR applications. (I've tested using ADL on desktop and it works, but I have been told that you won't be able to install an AIR application on desktop with this setup.) So for desktop you probably want to use the HTML workaround. This is supported in AIR for TV, so this would work on those devices.

How to pass vars from AIR App to external SWF

I am developing an air application where I have to drop an image and save the Image path, width, height to variables and pass those variables to external swf. I load the swf like this:
var myLoader:SWFLoader = new SWFLoader();
var url:URLRequest = new URLRequest("myExternalMovie.swf");
myLoader.load(url);
I am getting this error: the way I am passing the URL of the swf is incorrect and not supported in AIR.
Haven't encountered this one myself yet but, the first thing that came to mind is well what path should that be. That is if I look at some filename from an application am I concerned with a path relative to the application's current working directory from which it was executed or am I concerned with the application install folder and paths relative to there, looking at the docs it seems Adobe went down the same line of thought and provided the ability (and need) to specify:
http://livedocs.adobe.com/flex/3/html/help.html?content=url_requests_2.html#1030295
Was going to copy but basically read through the section titled
Using AIR URL schemes in URLs

Air: Possible? Writing into installed application package

This is probably a bad idea or whatever you wan't to call it. Nevertheless, curious to know if Air can write inside it's own installed package. I'm referring to the OSX '.app' files found in great numbers in the applications folder. Since every one of these can be opened as a regular folder, i'm guessing that's what they are.
What other fancy filewriting tricks am i missing out on?
It's definitely a bad idea. That said, it looks like it's probably possible. Something like (untested):
var appDir:File = File.applicationDirectory; // uses app: URI, can't be written to
var appPath:String = appDir.nativePath;
var writeableAppDir:File = new File(appPath);
var newFile:File = writeableAppDir.resolvePath("writeme.txt");
The nativePath and applicationDirectory documentation in the File class are full of warnings against this. Follow them.
From the docs:
Modifying content in the application
directory is a bad practice, for
security reasons. If you want to store
application-specific data, consider
using the application storage
directory
(File.applicationStorageDirectory). If
you want any of the content in the
application storage directory to have
access to the application-priveleged
functionality (AIR APIs), you can
expose that functionality by using a
sandbox bridge.

Open local file with AIR / Flex

I have written an AIR Application that downloads videos and documents from a server. The videos play inside of the application, but I would like the user to be able to open the documents in their native applications.
I am looking for a way to prompt the user to Open / Save As on a local file stored in the Application Storage Directory. I have tried using the FileReference + URLRequest classes but this throws an exception that it needs a remote url.
My last resort is just copying the file to their desktop : \
You can use the new openWithDefaultApplication(); function that's available on the File class (I believe it's only available in AIR 2)
eg:
var file:File = File.desktopDirectory.resolvePath(fileLocation);
file.openWithDefaultApplication();
Only way I could figure out how to do it without just moving the file and telling the user was to pass it off to the browser.
navigateToURL(new URLRequest(File.applicationStorageDirectory.nativePath + "/courses/" + fileName));
This is the first release of the FluorineFx Aperture framework.
The framework provides native OS integration (Windows only) support for AIR desktop applications.
The framework extends Adobe AIR applications in a non-intrusive way: simply redistribute the provided libraries with your AIR application, at runtime the framework will automatically hook into your application.
Features
Launch native applications and documents with the provided apsystem library
Take screenshots of the whole screen with the provided apimaging library
Access Outlook contacts from an Air application with the provided apoutlook library
http://aperture.fluorinefx.com/
Currently adobe is not supporting opening files in there default applications. Passing it off to the browser seems to be the only way to make it work.
You could however use a FileStream and write a small html file with some javascript that sets the location of an iframe to the file, then after 100ms or so calls window.close(). Then open that file in the browser.
For me it's:
var request:URLRequest = new URLRequest();
request.url = file.url;
navigateToURL(request, "_blank");
The navigateToURL(file.nativePath) didn't work since the path, "/users/mydirectory/..." was outside the application sandbox. AIR only allows some protocols to be opened with navigateToURL().

Resources