|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Flash Flash Meets Authorware
Flash Meets Authorware
Apr. 7, 2004 12:00 AM
In this article I show you some of the tricks I've learned over the years and give you some ideas for how to better combine Flash and AuthorWare in your work. I start with the basics and move to the more cpmplex, and I cover some optimization techniques for speeding up flash playback. You can find sample FLA and AW files at www.sys-con.com/mx/sourcec.cfm. XTRA or ActiveX For XTRA, Authorware version 6.0 supports Flash 5, while Authorware 6.5 and 7.0 support Flash MX. Flash MX 2004 is not currently supported as an XTRA and would require use of ActiveX. Regarding ActiveX, nearly everyone on Windows has a version of Flash ActiveX, but it is not guaranteed. I personally use XTRA because it will work on Macs and PCs, but many people use ActiveX or both ActiveX and XTRA. The samples in this article use XTRA. A Few Notes on Code
myArray["2", "4", "6"] In Authorware the first value in an array is referenced by 1; myArray[1] would equal "2". In Flash it is referenced by 0; myArray[0] would equal "2" while myArray[1] would equal "4". Inserting Flash into Authorware The Media and Playback options are pretty straightforward, but here are two items worth mentioning: Sending Messages from Flash to Authorware Flash talks to Authorware using the getURL("myMessage") function. You can add getURL() to buttons or in keyframes to let Authorware know an event has occurred or a specific frame has been reached. GetURL() sends a message, and you have to set Authorware to capture the message; you do this using an Event interaction. Drag an interaction icon to the Authorware flowline and add a calc icon to it. Then set the response type to Event, as shown in Image II. Once you have set this response type to Event, the interaction will switch from a button to an "E". Click the "E" to change the properties of the Event interaction. You need to set this interaction to listen for getURL commands from Flash movies. In the Sender section is a list of all the icons that send events that Authorware recognizes. In this sample I only have two Flash movies: "10_10_10" and "10_20_10". Double-click the icon (or icons) that interest you. When a "Sender" is selected, the Event field will display a few choices. We are looking for the getURL event, since that is what Flash is using to communicate (see Image III). Notice the "x" next to each name that has been double-clicked. You can double-click again to deselect one or more items. In Image III I have also double-clicked the getURL Event - it also has an "x". Note: You have to select an event for each sender. It may look like getURL is selected for both Icon 10_10_10 and Icon 10_20_10, but it is possible that getURL is only selected for Icon 10_20_10. Take your time to get this right, since this is a crucial part of communication. We still aren't quite finished; we have to capture the actual message sent from Flash and act upon it. This is done with only one line of code. In a calc icon in this Event interaction you need the following code: result:= EventLastMatched[#urlString] It may look complicated, but the code simply asks for the string sent from the Flash movie. The "result" will be whatever is sent from the getURL() function in Flash. GetURL("myMessage") in Flash would make "result" in Authorware equal "myMessage". Sending messages to Authorware makes it possible to use Flash to create menus or user interactions that can be directly acted upon in Authorware. This allows Flash to be a tool in your courseware, not merely a media type. Authorware to Flash Communicating from Authorware to Flash is simpler than communicating from Flash to Authorware. Authorware uses three main function types - CallSprite(), getSpriteProperty(), and setSpriteProperty(). Each function is relatively straightforward, but you have a lot more options than you have when you send messages from Flash to Authorware. Authorware uses CallSprite(@"Flash Icon", #setVariable, "myVariable", "myValue") to send messages to Flash. In Image IV, "myCount", a variable, which has to exist in Flash already, would be set to "5". Note: Even though 5 is a number and "myCount" is most likely a numeric value, the parameter passed has to be a string. Therefore, either wrap it in quotes or use the String() function in Authorware. If it isn't sent as a string, the value of the variable will not be changed in Flash. This Authorware sample has two icons, a Flash movie called "myFlash" followed by a calc icon that sets a variable in the "myFlash" movie called "myCount" to 5. The corresponding Flash movie file is one frame with a variable called "myCount" (initially set to "1") and a text box that displays "myCount". The text box properties look like Image V. I use the Var property since it automatically updates when "myCount" changes. Before getting to "The Hard Part" I want to wrap up with some other common functions used to communicate from Authorware to Flash. The corresponding function to #setVariable is #getVariable. result:=CallSprite(@"myFlash", #getVariable, "myCount") You can use this to verify that your #setVariable worked or to check a value if Flash is also changing a variable's value. Finally we have playback functions, which control the Flash movie timeline (see Code I). It may take a while to get used to these functions, but eventually they become second nature. The Rewards 4. Animated buttons: I've made a few courses with animated buttons that move to show progress. This can look very nice, but don't overdo it. The Hard Part I used Var because it's easy. There's nothing wrong with easy, but it's often more limited than other ways of doing things. The Var property updates automatically when its corresponding variable updates. However, when you set the text field in ActionScript code, it only updates when that code is run. You can also use dot syntax with #setVariable, so CallSprite(@"myFlash", #setVariable, " myTextFieldName.text", "5") would also work. But what happens if you want to do more than just display this variable in your Flash movie? If you need to modify the variable and respond to it, then you need to do it in ActionScript code. If you need to do it in code, then you need to ensure that all the necessary information is already in Flash before that code is executed. Many beginners have Flash loop so that the frame containing the needed code is hit often. This works, but it's inefficient and will use a lot of processing power. It also isn't very accurate if you need to act upon more than one simple piece of information. The second option is to use stop() functions in Flash and then use #setVariable followed by #play to hit the frame with your code in it after the variable has been set. This also works, but leads to awkward Flash files that are confusing to modify and update. With one variable, it isn't bad. But can you imagine a 100-frame animation with variables set at different times? This is the hardest part of using Flash in Authorware: responding to events and changes in a timely manner. It takes planning to create integrated projects that work the way you want without either using up processes by continuously looping or creating convoluted Flash files. Tips and Tricks Code for Flash Icons in Authorware "Movable@IconID" should be pretty easy to understand: it just means that a user can't drag the Flash movie around the screen. You may want to allow Movable at times, but usually I want my Flash movie to stay where I put it. The second line makes the variable "FlashID" a reference to your Flash icon, allowing you to modify the icon without referring to it by name. CallSprite(@FlashID...) Note: With "FlashID" you don't use quotes. Use @FlashID, not @"myFlash". Why is this helpful? A typical Authorware piece of mine may have a dozen or more Flash movies, and this code allows me to accomplish several things: Image VII shows some code that I've used for a global pause button. It should be placed in a perpetual button at the top of your flowline. For the pause/play button see Code II. It's that easy. You could also add other code here as well. You may want to tell the Flash piece it is inactive, or perhaps toggle the Direct to Screen property so that is doesn't take up as many resources. Code for Flash Movie Completed It is sometimes possible to use the following code in the active if field of your Continue button: getSpriteProperty(@FlashID, #Frame) = getSpriteProperty(@FlashID, #frameCount) This won't work, however, if the last frame has either submovie clips or actions the users need to complete. This is why I tend to add a line of code in each Flash piece letting Authorware know when I consider a movie to be complete. While occasionally you can get away with checking if the current frame is the last frame, it is easier to simply add a little code in Flash to tell Authorware when it is finished. Controlling Flash Files with Multiple Segments There are easy and hard ways to do this, with the easy way having more limitations. The easy way is to use #gotoFrame at the appropriate times to get to the part of the Flash movie that you want. Here are a few pointers: A more complex way of controlling Flash playback is to create a control frame in Flash. All navigation takes place from this frame based on a variable that is sent from Authorware. So while Authorware decides when and where to navigate, Flash actually handles the navigation internally. Authorware would use #setVariable indicating the desired scene and then would use #gotoFrame to the control frame. Since the control frame always uses goto(), it will never be the current frame for more than an instant. Advanced Data Sharing Passing Arrays to Flash temp:=Strip("[]",String(myArray)) 2. Send this value to the Flash Movie. CallSprite(@myFlash, #setVariable, "PreArray", temp) 3. Navigate to a frame containing the code in step 4. CallSprite(@myFlash,#gotoFrame, n) 4. Add the following code in Flash in frame 'n'. myArray=PreArray.split(",") 5. myArray is now an array in Flash that mirrors myArray in Authorware. Note: The two things to watch out for are commas in your Array and European deployment. In Europe, a semicolon is used to separate lists instead of a comma. If either of these is the case, you will need to loop through your array, adding each index to a string with a different, perhaps multicharacter, separator. A colleague suggested the following method for sending arrays. In this example you would need an empty array in your Flash Movie called "_array" (see Code III).] You must ensure that "_array" is empty, however, as this method will not clear out pre-existing indexes if the original array has a greater length than the new array. Multilinear arrays take more effort. I have had to create a pseudo-subroutine for those. I've never had to pass a property list (an associative array in Flash), but I imagine this could be done with a subroutine, as well. A Fake Listener in Flash Therefore, I built upon the control frame idea discussed before and created a control Movie Clip for my Flash movies. A simple control Movie Clip has two frames and continuously loops to check for new information from Authorware. Frame 1 is shown in Code IV; Frame 2 is shown in Code V. This is just a sample; Frame 2 could also be a case statement, and a real example would probably have more navigation options. On the Authorware side you only need to send one variable and everything else is taken care of by Flash. CallSprite(@FlashID, #setVariable, "authorwareEvent", "pause") or CallSprite(@FlashID, #setVariable, "authorwareEvent", "scene3") If you are fairly comfortable coding in Flash, an even better solution would be to use the Watch() function introduced in Flash MX (see Code VI). Code VI can be placed on the main timeline and does not require any looping. A Pseudo Subroutine This is too complex to describe here, but it can be done by looping a decision icon in Authorware that sends parent and children information for each Framework to Flash and then waits until Flash lets Authorware know that it has added the nodes to the tree Menu. Optimization Techniques for Flash Playback You should always:
You'll want to use Direct to Screen unless there is something else that you need to display above your Flash movie or if you need the Flash movie to be transparent. It may be necessary to toggle Direct to Screen on for complex scenes and off for standard use (SetSpriteProperty(@FlashID, #directToStage, true), SetSpriteProperty(@FlashID, #directToStage, false)) if you need that level of control. Setting Mode to Transparent is a wonderful feature, but it will slow things down, especially since you can't set the Flash movie to Direct to Screen. You only want to use transparency when you need to. There are modes other than Opaque and Transparent, but they don't seem to have any affect on Flash Movies, so stick to Opaque or Transparent. If you use Transparent, then also be sure to set Authorware's GlobalTempo to the same frame rate as your Flash Movie (Using 'GlobalTempo:=n') in an Authorware Calc.) If you still need to increase playback performance, you have additional options in the Options button from the Properties panel. Additional Options: - Lock-Step will match frames per second to Authorware's global tempo (which can be changed in Authorware with this code 'GlobalTempo:=n'). I believe this will force Flash to refresh at this rate. Flash Asset Help says this is the best performance of the three options. - Fixed allows you to set a playback rate to a specific fps rate. - Experiment to find what works best. There are other excellent tips in the Flash Asset documents [path to Authorware on your computer]\xtras\FlashAsset\Help\FlashAsset.html. If you're still having trouble, post a question to the Authorware Listserv http://listserv.cc.kuleuven.ac.be/archives/aware.html. This is an excellent resource where new users and experts exchange ideas and assistance, with Flash performance being a frequent topic. Conclusion If you are writing courseware that involves scheduling or history, consider whether the calendar component would make things easier. Would graphing components add a nice visual element? I hope that you are able to use these samples. Look for these and other source files on my Web site as well (www.guitar-learning.com/awflash). Happy Coding! Reader Feedback: Page 1 of 1
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||