So, let's do a little comparison. We've already seen what it takes to incorporate simple video into Flash and Flex. Now, let's say you have a bit of programming that you would like to turn into a SWC, which is a file format Flash-based applications use to store components. It is a self-contained file that can be loaded into other Flash applications to include its functionality into that app. It is a nice, compact, easily-transportable way to distribute code and components. So let's look at the difference between Flash and Flex in making SWC files. For our comparison, we'll assume that you have the component you want to make into a SWC all finished and available in your choice of application.
Here are the steps for making a SWC in Flash:
- Right-click on the component in your Flash file's Library panel and select the Export SWC File... option from the context menu.
- Select the place where you would like to export your SWC file to in the dialog box, give it a name, and hit OK.
- Enjoy your SWC
The process for Flex is a bit different:
- Create a custom class extending the Sprite class. This is pretty much a prerequisite for doing anything in Flex.
- Have your custom class import the files you want to turn into a SWC, and in your custom class declare a property of the same class type as the file you want to make into a SWC. Do this for each component you want to include in the SWC.
- Now right click on the Flex project and go to Properties. Select the Flex Compiler tab of the dialog box and enter in the compile command string specifying the file you want to convert into a SWC and where you want the compiled SWC to be output.
- Oh right, you can't do that in Flex. Cancel out of the dialog box and go to the command line in Windows. Yeah, the command line, that thing that should have become obsolete with the advent of Windows.
- Navigate to the directory housing your Flex compiler and use the compc command to use the component compiler to turn your file into a SWC.
- Wait, it says that it can't find the file. We probably need to run the compc command in the directory our file is in. Okay, okay.
- Right click on your My Computer icon and select Properties and then select the Advanced tab and then click on Environment Variables and then add onto the value of the Path variable the file path for the directory containing your Flex compiler. Follow that? Good.
- Return to the (antique) command line and navigate to the directory holding your SWC-to-be. Run the compc command to convert your file into a SWC.
- Hmm. It still says it can't find the file, but the file is right there. Okay. Let's try moving the file into different directories and try a series of options for the compc application to specify the location of the files to use.
- Huh. Those are some interesting errors. Uh, let's try asking your co-workers, who are more experienced than you, if they have a solution. They're very busy, but I'm sure this will be faster than banging your head against a wall.
- Okay, they're puzzled, too. Let's try including a library SWC of framework code that the application wants when we try to make the SWC.
- Well, that didn't work. Let's try running an ANT script that will automate the process and make it easier. This worked in another project.
- Hrm. It's not working in this project. In fact, it's still having the same problem as before where it can't find the file. Uh. Well. Uhm. Huh. I guess we'll try this some other time, okay?