Where Can I Buy Amoxicillin - FDA Approved Pharmacy

All About the Adobe Flash Platform

Archive for March, 2007

Apollo Multi-Window Support using Flex

with 12 comments

One of the most exciting features of Apollo is support for applications which have multiple native windows. Currently when using Flex in the browser, you are limited to using PopUpManager or rolling your own MDI architecture. With Apollo, your application can look more like, well... a native application. Each window will appear in the task bar on Windows, have a tab and z-order, etc. An existing issue in the Apollo alpha that you may struggle with if you are doing Flex development, is that the Flex Framework does not currently support Apollo's NativeWindow implementation. The issue stems from the fact that now your Apollo application can have multiple stages and the Flex framework which was originally developed for the browser player doesn't take this into consideration. Right now if you try to add Flex content, such as a custom Flex component, to a new windows stage you will get unexpected and broken behavior. Now, I wouldn't bring this up unless I had a solution. But before I show you that, a few caveats: a future release of the Flex Framework will formally support multiple windows. If you are looking at this article and there is currently a post-alpha Apollo release, please check the docs first to see if Flex officially supports multiple native windows. Another caveat: You will still run into a few issues and bugs when using this technique. For example, PopUpManager may not work properly in new NativeWindow instances. On to the code (the comments should explain what is going on): [xml] [/xml] [as] import mx.managers.FocusManager; [Bindable] private var newWindow:NativeWindow; private var component:TestComponent; private var componentFocusManager:FocusManager; // This function gets called when the button in the first // window is clicked. public function createNewWindow():void { // To make things easy for this demo, I am just checking // to see if the window is already open. If it is, I // don't do anything. if( !newWindow ) { newWindow = new NativeWindow( true, new NativeWindowInitOptions() ); // Make sure and set the stage alignment and scale // mode so that the Flex component we add to the // window appears correctly. newWindow.stage.align = StageAlign.TOP_LEFT; newWindow.stage.scaleMode = StageScaleMode.NO_SCALE; // Here is the secret sauce. Create a new instance // of a component which in this example is TestComponent, // an MXML component in the TestComponent.mxml file (not // shown.) Add it to our hidden canvas and then remove // it. This makes sure the component initializes based // on the current stage that the base Application refrences. component = new TestComponent(); hiddenCanvas.addChild( component ); hiddenCanvas.removeChild( component ); // Now we add that component to the new NativeWindow's // stage and register to know when the NativeWindow resizes. newWindow.stage.addChild( component ); newWindow.addEventListener( NativeWindowBoundsEvent.RESIZE, handle_windowResize ); // We want to make focus management work inside the // new window. So we create a new FocusManager for the // component. This doesn't 100% work, but it atleast // allows you to tab through most components. component.focusManager = new FocusManager( component, true ); component.focusManager.activate(); component.focusManager.showFocus(); } } public function handle_windowResize( event:NativeWindowBoundsEvent ):void { // The window resized, so lets make sure and resize // the Flex component. component.width = newWindow.stage.stageWidth; component.height = newWindow.stage.stageHeight; } [/as]

Written by Daniel Dura

March 30th, 2007 at 8:01 am

Posted in AIR, Flex, Tutorial

Apollo Native File Dialogs

with 6 comments

Currently the Apollo Alpha doesn't support native file dialog boxes (it will before the final official release.) Despite that, there is a way to get this functionality now by using existing Flash Player APIs. I will first show how to display a file 'Save' dialog box which allows the user to specify the name of the file they would like to write to the disk. This will allow them to type in the name of a file that may not exist. The user can also select a file that already exists and the dialog will prompt the user that they are about to replace that file on the system. To accomplish this in Apollo, you use the 'download' method on the flash.net.FileReference class. Because the flash.filesystem.File class extends FileReference, you can employ this technique by using that class as well. The trick to getting the File reference without actually downloading the file is to cancel the URLRequest before it executes. See the code below for an example: [as] private var file:File; private function saveFile():void { // Here we create a new File class and wait for the // 'open' event. The URLRequest can use a URI pointing // to any resource, we will be canceling it in the event // handler. It must be a valid URI though. We also specify // the default name for the file that the user will be able // to override in the dialog. file = new File(); file.addEventListener( Event.OPEN, handle_saveFileSelect ); file.download( new URLRequest("http://foo"), "hello.txt" ); } private function handle_saveFileSelect( event:Event ):void { // First cancel the download operation. We aren't going // to download a file but we now have a reference to the // file the user specified anyways! file.cancel(); // Time to write out some text to the file. var fileStream:FileStream = new FileStream(); fileStream.open( file, FileMode.WRITE ); fileStream.writeUTF( "Hello World!" ); fileStream.close(); } [/as] Another File dialog that you may want to use is a file chooser dialog. This dialog will only allow the user to select only existing files. We can actually use this API as documented we don't have to cancel any URLRequests like in the previous example.This can be accomplished by using the flash.filesystem.File 'browse' method. Lets take a look at the code: [as] private var file:File; private function readFile():void { file = new File(); // Lets listen for the 'select' event. This event tells us that // the user selected a file. We can also listen for a 'cancel' // event that will tell us the user didn't select a file and // closed the dialog. file.addEventListener( Event.SELECT, handle_readFileSelect ); // Open the dialog box and wait for the 'select' event. file.browse(); } private function handle_readFileSelect( event:Event ):void { // Get a reference to the file and trace out the // text representation of the file. file = File( event.target ); var fileStream:FileStream = new FileStream(); fileStream.open( file, FileMode.READ ); trace( fileStream.readUTF() ); fileStream.close(); } [/as] To get a reference to more than one FileReference objects, you use the flash.net.FileReferenceList class. I will not show an example of that here, but it follows the same pattern as above. Be sure to check out the FileReferenceList docs. There are some limitations to these techniques and issues that you should be aware of:
  • There is no directory chooser dialog. You can only select or create file references.
  • You cannot specify an initial directory for the dialog. It will default to the directory of the last file that was selected.
  • Each Apollo application can only have a single file dialog box open at any given time. This means that each window of an Application is limited to the one dialog for its parent application.
I have attached a simple Flex Builder Project file that contains all of the code above.

Written by Daniel Dura

March 29th, 2007 at 6:24 am

Posted in AIR, Actionscript, Tutorial