| | Next |
AS2.0 to AS3.0 Migration and the Missing Documentation
We are working better mProjector AS3 documentation but it's not fully ready. Most functionality is similar to AS2-based mProjector V3, so we thought we'd get a release out using the AS2 docs BUT please note the following IMPORTANT DIFFERENCES.
Differences between the AS2 and AS3 implementation of mProjector's Desktop Classes:
- Include the mProjector AS3 component and an "import" statement before using mProjector methods.
- Use addEventListener() to register your mApplication, mWindow, and mMenu event handlers.
- Use addEventListener() to register your download file progress event handler.
- Use mWindow.addCallback() to register your methods for Window to Window communication.
- Use mApplication.setSystemTrayIconFromFile() instead of mApplication.setSystemTrayIcon().
- mProjector v4 classes are no longer global. To access mProjector classes make sure your FLA document library (Flash) or project library path (Flex) contains the mProjector component (SWC in Flex).
Call import stm.mprojector.mProjectorClassName before using the mProjector method.
import stm.mprojector.mWindow;
mWindow.setPosition(50, 50);// set the window position to x=50, y=50 on the desktop.
- mProjector Application, Window, and Menu event handlers, such as mApplication.onActivate(), have be replaced in the new AS 3.0 style event model where you add event listeners via className.addEventListener().
The sample code below hooks up an event listener for each mProjector event type.import stm.mprojector.*; import stm.common.*; public function initListeners():void { mApplication.addEventListener(mApplicationEvent.ACTIVATE, applicationEventHandler); mApplication.addEventListener(mApplicationEvent.SCREEN_CHANGE, applicationEventHandler); mApplication.addEventListener(mApplicationEvent.MESSAGE, applicationEventHandler); mApplication.addEventListener(mApplicationEvent.SYSTEM_TRAY, applicationEventHandler); mApplication.addEventListener(mApplicationEvent.DOWNLOAD_FILE_PROGRESS, applicationEventHandler); mWindow.addEventListener(mWindowEvent.ACTIVATE, windowEventHandler); mWindow.addEventListener(mWindowEvent.DRAG_FILES, windowEventHandler); mWindow.addEventListener(mWindowEvent.DROP_FILES, windowEventHandler); mWindow.addEventListener(mWindowEvent.MINIMIZE, windowEventHandler) mWindow.addEventListener(mWindowEvent.MAXIMIZE, windowEventHandler); mWindow.addEventListener(mWindowEvent.RESTORE, windowEventHandler); mWindow.addEventListener(mWindowEvent.SCROLL_WHEEL, windowEventHandler); mMenu.addEventListener(mMenuEvent.COMMAND, menuEventHandler); } public function applicationEventHandler(e:mApplicationEvent):void { mApplication.trace(new Date().toString() + ": mApplication " + e.type + " event "); switch (e.type) { case mApplicationEvent.ACTIVATE: mApplication.trace(new Date().toString() + ": mApplication " + e.type + " event - active: " + e.active.toString()); break; case mApplicationEvent.RESTART: mApplication.trace(new Date().toString() + ": mApplication " + e.type + " event - args: " + e.args.toString()); break; case mApplicationEvent.DOWNLOAD_FILE_PROGRESS: mApplication.trace(new Date().toString() + ": mApplication " + e.type + " event - sessionID: " + e.sessionID.toString() + " total: " + e.total.toString() + " read: " + e.total.toString()); break; case mApplicationEvent.MESSAGE: mApplication.trace(new Date().toString() + ": mApplication " + e.type + " event - message " + e.message); break; case mApplicationEvent.SCREEN_CHANGE: case mApplicationEvent.SYSTEM_TRAY: mApplication.trace(new Date().toString() + ": mApplication " + e.type + " event "); break; default: mApplication.trace(new Date().toString() + ": mWindow " + e.type + " event - UNKNOWN EVENT TYPE "); } } public function windowEventHandler(e:mWindowEvent):void { switch (e.type) { case mWindowEvent.ACTIVATE: mApplication.trace(new Date().toString() + ": mWindow " + e.type + " event: " + e.active.toString()); break; case mWindowEvent.DRAG_FILES: mApplication.trace(new Date().toString() + ": mWindow " + e.type + " event - files: " + e.files.toString()); break; case mWindowEvent.DROP_FILES: mApplication.trace(new Date().toString() + ": mWindow " + e.type + " event - files: " + e.files.toString()); case mWindowEvent.SCROLL_WHEEL: mApplication.trace(new Date().toString() + ": mWindow " + e.type + " event - string: " + e.scrollDelta); break; case mWindowEvent.MINIMIZE: case mWindowEvent.MAXIMIZE: case mWindowEvent.RESTORE: mApplication.trace(new Date().toString() + ": mWindow " + e.type + " event "); break; default: mApplication.trace(new Date().toString() + ": mWindow " + e.type + " event - UNKNOWN EVENT TYPE "); } } public function menuEventHandler(e:mMenuEvent):void { switch (e.type) { case mMenuEvent.COMMAND: mApplication.trace(new Date().toString() + ": mMenu " + e.type + " event - Menu: " + e.menu + " Item: " + e.item); break; default: mApplication.trace(new Date().toString() + ": mMenu " + e.type + " event - UNKNOWN EVENT TYPE "); } // handle menu selection } - The AS2 mApplication.downloadFile() API have be replaced in the new AS 3.0 style event model. First define an event handler then register it with the mApplication class. The event object includes read and total bytes like mProjector AS2 implementation and adds a sessionID property. As with AS2, when you are returned read = total = 0, the download has failed.
// Download File Event Handler import stm.mprojector.*; function downloadProgress(e:mApplicationEvent):void { mApplication.trace("sessionID: " + e.sessionID.toString() + " total: " + e.total.toString() + " read: " + e.total.toString()); } mApplication.addEventListener(mApplicationEvent.DOWNLOAD_FILE_PROGRESS, downloadProgress); var sessionID:uint = mApplication.downloadFile(localFileName.jpg, /temp/1.jpg); - The AS2 window to window communication API have be replaced with an flash.external.ExternalInterface style implementation where you define a communication method then register it as callable with the window's mWindow class.
mProjector V4 AS3 implementation
// ActionScript in child.swf import stm.mprojector.mWindow; // define function function messageReceiver (message: String):void { message.text = message; }; // register messageReceiver as callable by other windows. mWindow.addCallback("messageReceiver", messageReceiver); // ActionScript in parent.swf childWindow = mApplication.createWindow( "child.swf ", 50, 50, "CHILD ", "CHILD ", "STANDARD ", 160000, true, 100, true, true); if (childWindow != null) { mApplication.trace( "childWindow: " + childWindow.toString()); childWindow.messageReceiver( "hello from parent "); } };
mProjector AS2 implementation
// ActionScript in child.swf mWindow.messageReceiver = function (message: String):void { message.text = message; }; // ActionScript in parent.swf childWindow = mApplication.createWindow( "child.swf ", 50, 50, "CHILD ", "CHILD ", "STANDARD ", 160000, true, 100, true, true); if (childWindow != null) { mApplication.trace( "childWindow: " + childWindow.toString()); childWindow.messageReceiver( "hello from parent "); } }; - mProjector 4 no longer supports mApplication.setSystemTrayIcon(). Using mApplication.setSystemTrayIconFromFile() sets the icon in the Mac Application menu bar or the PC system tray to be the icon file specified. On the Mac, the icon will appear in the empty space on the right side of the Mac OS X application menu bar. On both platforms, icon will be 16x16 pixel. You can animate this icon to alert the user by setting to a sequence of icns (Mac) or ico (PC) files. Calling mApplication.showInSystemTray(true) without calling mApplication.setSystemTrayIconFromFile(fileName) will simply show the icon of the application itself in the menu bar.
| Questions or Feedback? | | Next |
More Information
Getting Started
ActionScript 3.0 Support
- AS2 Migration
- Getting Started - Flash
- Debugging in Flash
- Building your application from inside Flash
- Getting Started - Flex
- Debugging in Flex
ActionScript 3.0 Samples
Using mProjector
- Using mProjector - Compile Your SWF into an Appli
- Customizing The About Window
- Debugging Your Application
- Launching Application at Startup
- Mac vs. Windows Application Development
- Menus
- Dynamic Window Creation
ActionScript 2.0 Samples
- Application Basics
- mProjector Class Basics
- Add Remove Programs Control Panel
- Fullscreen and Center
- Check Connection and Download File
- Choose Files
- Creating an Installer
- Creating and Controlling Multiple Windows
- Cut, Copy, and Paste (Windows)
- Desktop Shortcut and Start Menu Support
- Drag and Drop Files
- Embedding HTML and other Media types
- Flash-Shaped Windows
- Message Box
- Open Documents
- Project Files
- Reading and Writing to Hard Drive
- Startup Application
- Wallpaper and Screensaver
- Window to Window Communications
- Working with Included Files
- Context Sensitive Menus
- Alert User
- Screen Resolution
