This content has been marked as final. Show 4 replies
quote:The main thing you must understand about air.swf is that its most important functionality can only be called from within a UI event handler, such as for a button click. It's very picky about this. You can't, for example, use the button click event handler to begin the loading of air.swf, then in the "loaded" callback do the air.swf API call. air.swf has to be loaded and ready at the time the event handler is called. So, load it on app startup. I even go to the extent of disabling the buttons that call into air.swf until it's loaded.
Originally posted by: cjm771
can't manage to figure out how the air.swf api works
quote:The appid is your application's unique ID, which you gave in setting up your project. Adobe recommends using something based on your web site's domain name, in reverse order as is done in Java and Objective C. If you're at foo.com, and call your program Qux, then com.foo.qux is a good appid. The use of domain-like names helps ensure that programs from different companies don't collide with each others' namespaces.
im a bit unclear on where i get appid or developer id
By default, the pubid is a random number assigned by the IDE. I forgot how you find out what number it used, just that there's a way. Or, you can assign it yourself, in the project settings for the AIR app. Right-click the project, go to the Run/Debug Settings section, edit the launch configuration for your AIR app. You'll find a Publisher ID field there. The documentation for ADL may be helpful for picking your own pubid.
quote:See my code in this thread: http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=75&catid=697&threadid =1352505&highlight_key=y&keyword1=air%2Eswf
if someone has an example app or more in-depth explantion of incorporating the given code , i would much appreciate it.
You're misunderstanding the purpose of the version check.
My application -- from which that code is extracted -- comes in two flavors, AIR and Flex, both with the same version number. This code lives in the Flex flavor of the app. When it sees that the AIR flavor of the app is installed, it checks its version number to see if it's the same as the Flex flavor's version number, which is always up to date since it's served from a single public web site. If not, it figures the Flex flavor of the app got updated since the last time you installed the AIR flavor, so it offers to upgrade your copy of the AIR app.
As for the "format" of that code, there's a command in Flex Builder to reformat the code. On doing that, you'll see that there are several functions, but they're all defined as closures within the one big public function, checkForAirVersion(). Thus, the entire feature is encapsulated. The Flex flavor of my app just calls this at startup, and it takes care of everything: it starts air.swf loading, then on successful load, it sets up the UI event handlers for calling back into air.swf from button clicks in the Flex app.
You may not have come across closures before. They're very powerful and useful, if a bit confusing at first. This bit of code shows why they're nice to have: we can define functions that use variables from an outer scope that don't get values until later, and ensure that those closures don't get called until the variables do get good values. You could mimic this by defining it all in a class, but, well, this is ActionScript, not C++. :) Classes are grafted onto AS, while closures are a first class feature.