Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the last video, we talked about how to create a SWC file, and what we did here is we connected the extension development with the extension consumption. So everything that makes up an extension--the descriptor, the ActionScript code, the native code, and all the resources for each platform--is all assembled into this SWC file. Now what we have to do is we have to take this SWC file and package this up into an ANE file, and the ANE file is what the Flex developer adds to their project, and then they can utilize these ActionScript APIs that we defined in our class and these ActionScript APIs, as you see, if I scroll down here, right, this ActionScript API connects back to the native code through the call function, which is very powerful.
And again, all of this is hidden from the Flex developer. They can simply just import this, link it to the ANE file, and be able to utilize all of these native extensions. So, very, very powerful. Now to actually create this ANE file, we have to do a bunch of different things. So not only do we have to utilize this SWC file, but we have to utilize the contents of the SWC file. So what I am going to do is I am just going to copy this SWC file to my clipboard, so I am going to say Copy, and then I am going to go to my desktop.
And what I am going to do is I am going to paste the SWC file onto my desktop. So I will just say, Edit > Paste, and I will paste that SWC file onto my Desktop. Now for those of you who are familiar with Java, a SWC file is very, very similar to a JAR file. It's just simply a ZIP-based file that contains a whole bunch of different assets. So what I can do is just a Get Info, and I can rename this to a ZIP file. And I will just say use .zip and I will simply unpack the ZIP file like so, and this will create me a directory of all of the assets inside of this SWC file.
You should see the catalog.xml and the library.swf file. Now, we have to use this library.swf file in order to generate an ANE file. Now the extension packages, when we create these ANE files, we utilize the AIR Developer tool. Now this is a command line tool, and this is available in both the Flex and AIR SDKs. And the AIR Developer tool is the same tool used to package AIR applications for deployment, and the options used to create ANE files are very, very similar.
So again, I'm going to assume that we have all of the resources inside of the same directory. You could place them, for example, in this Vibrate directory. And then you of course have to have the global environmental variable set up, and the process is different for that on Mac and for Windows, so that you can access that AIR Developer tool. I'm not going to cover how to set up the AIR Developer tool, but you can catch that in other lynda.com courses that cover AIR and the Flex SDK.
So now once you have that AIR Developer tool set up, you can just simply go to the command line and browse to the directory where all of your files and resources are. In our case this is the Vibrate directory. So let's take a look at how to actually do that and build an ANE file. Now we have to do this at the command line. And the first thing we do is we type in the command adt and we type in what type of package we want to create, and what type of target. So you can see we just use ane for the target. And then we indicate the name that we want our new ane file to have. In this case, we are calling it MyExtension.ane.
Now next comes the path to the extension-descriptor and to the SWC file that defines the ActionScript API. So this extension-descriptor, if I just go right back to my desktop, you will see this in this case is called catalog.xml. This is our extension-descriptor. Now I would have to take this and rename this back to the SWC file, so let me do that. Okay, and what I will do is I will just Get Info and I'll call this again, a swc. Again I'll say use .swc, so I will just move that SWC to that same directory.
Now you'll see that SWC file is there as well. You'll see, so I am pointing it to that extension-descriptor.xml--in our case, I will just call catalog.xml--and then I'm saying this SWC, and again, this is all assuming everything is in the same directory. You could of course place the paths, if they were not in the same directory. And then I am going to point in to the actual SWC file. Now after this comes one or more sequences which specifies the individual sets of files necessary for each platform.
So for example, if I wanted to support the iOS platform, I would simply specify platform iPhone-ARM, and then I have to indicate the library.swf. And this is the APIs in ActionScript that connect back to the native API. So you have to say library.swf. This is the reserved name. Again, the same implementation in this example is used on both platforms, but you could use different SWF files if you wanted to.
So it still needs to be called library.swf, but it could be different settings. So, for example, here it is on the Mac platform, and I could also of course put in the Android platform. But you can see, again, I'm utilizing the library.swf, I am saying MacOS-x86, and then I am specifying where that is. So now remember, this is a very simple example. We contained only the minimally necessary library.swf in the library and the framework for each target platform, but remember, for the default platform, only library.swf is required.
And remember, in real life you're probably going to have lots of other additional files in that same SWC file. So for example, you might have images, you might have sound files, you might have resource bundles, and so on. And again, we are just utilizing this as a very, very simple example. So again, the root catalog.xml and the library.swf are taken from the specified SWC file. And again, if the swc did contain any other files, such as image or sound files, you would need to add those to the same directory before you build out the ANE file.
So that is the process of how to build an ANE file and how to link it back to your project.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 104443 Viewers
56 Video lessons · 116353 Viewers
71 Video lessons · 85590 Viewers
131 Video lessons · 40968 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.