4 Replies Latest reply on Jun 30, 2008 10:22 PM by Oliver Goldman

    working with badge.swf and air.swf (browser api)

    cjm771
      I basically want to install and run my app through the browser so ive been testing but can't manage to figure out how the air.swf api works. i am stuck at loading air.swf. the page below has a tutorial but a downloadable sample code would be perfect, not sure where the little snippets of code from the "Loading the air.swf file", "Checking from a web page if an AIR application is installed", "installing an AIR application from the browser", and "Launching an installed AIR application from the browser" go in my own codebase. Also im a bit unclear on where i get appid or developer id. if someone has an example app or more in-depth explantion of incorporating the given code , i would much appreciate it.

      http://livedocs.adobe.com/flex/3/html/help.html?content=distributing_apps_3.html
        • 1. Re: working with badge.swf and air.swf (browser api)
          Dr. Fred Mbogo Level 1
          quote:

          Originally posted by: cjm771
          can't manage to figure out how the air.swf api works
          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.

          quote:

          im a bit unclear on where i get appid or developer id
          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.

          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:

          if someone has an example app or more in-depth explantion of incorporating the given code , i would much appreciate it.
          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
          • 2. Re: working with badge.swf and air.swf (browser api)
            cjm771 Level 1
            thanks for the information i just have a few quick questions. I know you said to call checkForAirVersion(flexversion) before it is loaded, just wondering how that looks (whether it is under the function or within a button click attribute or etc) also, how do i get the version of flex, do i type it in manually or is there a function or variable that will automatically detect it? Thanks for the help, im familiar with java, javascript, and php but kinda new to flex/air.
            • 3. Re: working with badge.swf and air.swf (browser api)
              Dr. Fred Mbogo Level 1
              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.