Skip to main content
Inspiring
July 25, 2007
質問

AIR Intrinsic Classes-Tried and Proven Approach to building AIR applications in the Flash CS3 IDE

  • July 25, 2007
  • 返信数 3.
  • 287 ビュー
Hi everyone,

For all of you out there who would like to develop AIR applications
from the Flash CS3 IDE but aren't sure how to get those pesky intrinsic
classes working, I have a technique that you can work with to create
your classes and make fully functional AIR applications.

First of all, those solutions out there that list "intrinsic" functions
in their class definitions won't work. That keyword has been taken out
and simply won't work. The "native" keyword also doesn't work because
Flash will reject it. The solution is to do dynamic name resolution at
runtime to get all the classes you need.

Here's a sample class that returns references to the "File",
"FileStream", and "FileMode" classes:

package com.adobe{


import flash.utils.*;
import flash.display.*;

public class AIR extends MovieClip {

public static function get File():Class {
try {
var classRef:*=getDefinitionByName('flash.filesystem.File');
} catch (err:ReferenceError) {
return (null);
}//catch
return (classRef);
}//get File

public static function get FileMode():Class {
try {
var classRef:*=getDefinitionByName('flash.filesystem.FileMode');
} catch (err:ReferenceError) {
return (null);
}//catch
return (classRef);
}//get FileMode

public static function get FileStream():Class {
try {
var classRef:*=getDefinitionByName('flash.filesystem.FileStream');
} catch (err:ReferenceError) {
return (null);
}//catch
return (classRef);
}//get FileStream

}//AIR class

}//com.adobe package

I've defined the package as com.adobe but you can call it whatever you
like. You do, however, need to import "flash.utils.*" because this
package contains the "getDefinitionByName" method. Here I'm also
extending the MovieClip class so that I can use the extending class
(shown next) as the main Document class in the Flash IDE. Again, this is
entirely up to you. If you have another type of class that will extend
this one, you can have this one extend Sprite, Math, or whatever else
you need (or nothing if it's all the same to you).

Now, in the extending class, the Document class of the FLA, here's the
class that extends and uses it:

package {

import com.adobe.AIR;


public class airtest extends AIR{


public function airtest() {
var field:TextField=new TextField();
field.autoSize='left';
this.addChild(field);
field.text="Fileobject="+File;
}//constructor


}//airtest class

}//package

Here I'm just showing that the class actually exists but not doing much
with it.

If you run this in the Flash IDE, the text field will show "File
object=null". This is because in the IDE, there really is no File
object, it only exists when the SWF is running within the Integrated
Runtime. However, when you run the SWF as an AIR application (using the
adl.exe utility that comes with the SDK, for example), the text field
will now show: "File object=[object File]". Using this reference, you
can use all of the File methods directly (have a look here for all of
them:
http://livedocs.adobe.com/labs/flex/3/langref/flash/filesystem/File.html).

For example, you can call:

var appResource:File=File.applicationResourceDirectory;

This particular method is static so you don't need an instance. If you
do (such as when Flash tells you the property isn't static), simply
create an instance like this:

var fileInstace:File=new File();
fileInstance.someMethod('abc'); //just an example...read the reference
for actual function calls

Because the getter function in the AIR class returns a Class reference,
it allows you to perform all of these actions directly as though the
File class is part of the built in class structure (which in the
runtime, it is!).

Using this technique, you can create references to literally *ALL* of
the AIR classes and use them to build your AIR application. The beauty
of this technique is its brevity. When you define the class reference,
all of the methods and properties are automatically associated with it
so you don't need reams of code to define each and every item.

There's a bit more that can be done with this AIR class to make it
friendlier and I'll be extending mine until all the AIR classes are
available. If anyone's interested, feel free to drop me a line or drop
by my site at http://www.baynewmedia.com where I'll be posting the
completed class. I may also make it into a component if there's enough
interest. To all of you who knew all this already, I hope I didn't waste
your time.

Happy coding,
Patrick
このトピックへの返信は締め切られました。

返信数 3

Inspiring
July 27, 2007
Wow, you're right. The content simply doesn't show up at all. No
JavaScript or HTML parsing errors, apparently. But no IE7 content.

I'll definitely have to look into that. In the meantime, try FireFox :)

I'm trying to develop a panel to output AIR applications from within the
Flash IDE. GSkinner has one but I haven't been able to get it to work
successfully. Mine has exported an AIR app already so that's a step in
the right direction but JSFL is a tricky beast, especially when trying
to integrate it using MMExecute strings.

But, if you can, create AIR applications by hand. I haven't yet seen an
application that allows you to change every single option like you can
when you update the application.xml file yourself. Also, it's a great
fallback skill to have.

Let me know if you need some assistance with AIR exports. Once you've
done it a couple of times, it becomes pretty straightforward.

Patrick

GWD wrote:
> P.S. I've clicked on your link a few times over the last couple of days to
> check it out but all I get is a black page with a BNM flash header and no way
> to navigate to any content. Using IE7 if that's any help.
>
>
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
Inspiring
July 26, 2007
P.S. I've clicked on your link a few times over the last couple of days to check it out but all I get is a blank page with a BNM flash header and no way to navigate to any content. Using IE7 if that's any help.

Inspiring
July 26, 2007
Thanks for posting this info Patrick..

I've been meaning to give it a shot - I'll get there soon I guess. I read this a couple of weeks back but haven't tried that either:

http://www.gskinner.com/blog/archives/2007/07/creating_air_pr.html