3 Replies Latest reply on Apr 14, 2011 8:25 AM by bteran

    Coercion Error


      I'm currently receiving this error when using a tutorial-based code (from the official Adobe help docs...slightly modified, only by variable name).


      "Description    Resource    Path    Location    Type
      1067: Implicit coercion of a value of type Function to an unrelated type flash.display:Sprite.    ARC.mxml    /ARC/src    line 61    Flex Problem"



      It shouldn't be an issue, but I can't seem to crack it...if anyone has any thoughts it'd be greatly appreciated. Sincere thanks in advance.


      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                              applicationComplete="init()" backgroundColor="#323232" currentState="login" height.login="900" width.login="1280">
          <fx:Style source="ARC.css"/>
                  import air.net.URLMonitor;
                  import air.update.ApplicationUpdaterUI;
                  import air.update.events.UpdateEvent;
                  import flash.events.NativeWindowBoundsEvent;
                  import flash.events.UncaughtErrorEvent;
                  import flash.filesystem.File;
                  import flash.filesystem.FileMode;
                  import flash.filesystem.FileStream;
                  import flash.net.dns.AAAARecord;
                  import mx.controls.Alert;
                  import mx.events.AIREvent;
                  import mx.events.CloseEvent;

                  protected var monitor:URLMonitor;
                  protected var appUpdater:ApplicationUpdaterUI = new ApplicationUpdaterUI(); // Used for auto-update
                  protected var file:File; // Used for preferences file
                  protected var currentVersion:String="1.0"

                  protected function resolutionCheck(event:CloseEvent):void
                      //Check if the warning was acknowledged.
                      if(event.detail == Alert.OK)
                  protected function init():void

                      // Request to be notified when this application is activated (brought forward as the active window)
                      // or deactivated
                      addEventListener(AIREvent.APPLICATION_ACTIVATE, onAppActivate);
                      addEventListener(AIREvent.APPLICATION_DEACTIVATE, onAppDeactivate);
                      //Attempt to Maximise to Screen Dimensions
                      nativeWindow.height = (Capabilities.screenResolutionY);
                      nativeWindow.width = (Capabilities.screenResolutionX);
                      if(Capabilities.screenResolutionX <= 1280 || Capabilities.screenResolutionY <= 800)
                          Alert.show("This application requires a minimum screen resolution of 1280x800 to operate. " +
                                      "Please modify your screen resolution to meet the requirements and relaunch the application.",
                                      "Screen Resolution Inadequate", Alert.OK, resolutionCheck);
                      // Center main AIR app window on the screen
                      nativeWindow.x = (Capabilities.screenResolutionX - nativeWindow.width) / 2;
                      nativeWindow.y = (Capabilities.screenResolutionY - nativeWindow.height) / 2;
                      // Invoke listener - request to be notified when the AIR app is invoked (started), this could occur from the command line, UI or
                      // from opening an associated file
                      NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);

                      // Detecting online/offline network connectivity with a URLMonitor
                      monitor = new URLMonitor(new URLRequest("http://www.adobe.com")); // change URL to URL desired
                      monitor.addEventListener(StatusEvent.STATUS, onStatusChange);
                      monitor.pollInterval = 20000;// Milliseconds

                      // Check for update

                      // Detects a general change in network status
                      NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE,onNetworkChange );

                      // Detecting if user is present
                      NativeApplication.nativeApplication.idleThreshold = 5;
                      NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, onUserIdle);
                      NativeApplication.nativeApplication.addEventListener (Event.USER_PRESENT, onUserPresent);

                      // Get notified when minimize/maximize occurs
                      addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, onDisplayStateChange);

                      // Get notified when window resizing occurs

                      // Get notified whan a global error occurs
                      loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, errorHandler);

                      // Create a native menu with two items in the top-level application menu.
                      var item1:NativeMenuItem;
                      if (NativeApplication.supportsMenu)
                          var nativeMenu:NativeMenu = new NativeMenu();
                          item1 = new NativeMenuItem("File");
                          var item2:NativeMenuItem = new NativeMenuItem("Window");

                          var menuItem:NativeMenuItem = new NativeMenuItem("My App Menu");
                          menuItem.submenu = nativeMenu;
                      else if (NativeWindow.supportsMenu)
                          var menu:NativeMenu = new NativeMenu();
                          nativeWindow.menu = menu;
                          item1 = stage.nativeWindow.menu.addItem(new NativeMenuItem("My App Menu"));

                      // Manually close all open Windows when app closes.

                      // Create a file for storing preferences in the application storage directory
                      file = File.applicationStorageDirectory;
                      file = file.resolvePath("Preferences/version.txt");
                      trace("Preferences file location: " + file.nativePath);
                      if (file.exists)
                      else firstRun();

                  // The application is now in the foreground and active
                  protected function onAppActivate(event:Event):void {
                      trace("Handling application activate event");

                  // Handle the application being sent to the background
                  protected function onAppDeactivate(event:Event):void {
                      trace("Handling application deactivate event");
                  }// Called when application is first invoked
                  protected function onInvoke(invokeEvt:InvokeEvent):void
                      trace("Handling invoke event");
                  }// Handles when the HTTP Network status has changed.
                  protected function onStatusChange(e:StatusEvent):void
                      if (monitor.available)
                          trace("Network is online");
                      } else {
                          trace("Network is offline");
                  }// This function is triggered when the application finished loading.
                  // Initialize appUpdater and set some properties
                  protected function checkUpdate():void
                      // set the URL for the update.xml file
                      appUpdater.updateURL = "http://www.myappurl.com/update.xml";
                      appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate);
                      appUpdater.addEventListener(ErrorEvent.ERROR, onUpdaterError);
                      // Hide the dialog asking for permission for checking for a new update.
                      // If you want to see it just leave the default value (or set true).
                      appUpdater.isCheckForUpdateVisible = false;

                  // Handler function triggered by the ApplicationUpdater.initialize.
                   // The updater was initialized and it is ready to take commands.
                  protected function onUpdate(event:UpdateEvent):void
                      // start the process of checking for a new update and to install

                  // Handler function for error events triggered by the ApplicationUpdater.initialize
                  protected function onUpdaterError(event:ErrorEvent):void
                  }// The network status has changed
                  protected function onNetworkChange(e:Event):void
                      trace("Network State Changed");
                  }// Called when the user is idle
                  protected function onUserIdle(event:Event):void {
                      trace("Handling user idle event");

                  // Called when the user is active again - status will change if idle for more than 5 seconds
                  protected function onUserPresent(event:Event):void
                      trace("Handling user present event");
                  }// Handles when the app is minimized/maximized
                  protected function onDisplayStateChange(e:NativeWindowDisplayStateEvent):void
                      trace("Display State Changed from " + e.beforeDisplayState + " to " + e.afterDisplayState);
                  }// Called when window is resized
                  protected function onWindowResize(event:NativeWindowBoundsEvent):void
                      trace("Window resizing");
                  }// Handle Global Errors
                  protected function errorHandler(e:UncaughtErrorEvent):void
                      Alert.show("An error has occurred and been caught by the global error handler: " + e.error.toString(), "My Global Error Handler");
                  }// Handle Menu item selection
                  protected function onItemSelect(e:Event):void
                      trace("Menu item selected");
                  // Called when application window closes
                  protected function onAppWinClose(e:Event):void
                      trace("Handling application window close event");

                  // Closes all open windows
                  protected function closeOpenWindows(e:Event):void
                      // This code can be uncommented to prevent the default close action from occurringand first call the close method on each open window to
                      // perform any actions needed. Closes each from most recently opened to oldest.
                      //for (var i:int = NativeApplication.nativeApplication.openedWindows.length - 1; i>= 0; --i)
                  // Check for current version from saved prefs file. If no file exists, this is the first time run
                  protected function checkVersion():void
                      var stream:FileStream = new FileStream();
                      stream.open(file, FileMode.READ);
                      var prevVersion:String = stream.readUTFBytes(stream.bytesAvailable);
                      if (prevVersion == currentVersion) {
                          trace("Current version running");

                  protected function firstRun():void
                      trace("First time the application has been run, save to the file.");

                  protected function writeVersionFile():void
                      var stream:FileStream = new FileStream();
                      stream.open(file, FileMode.WRITE);
                  }        ]]>
              <s:State name="login"/>
              <s:State name="dashboard"/>
          <s:Label text="Welcome to ARC." fontSize="20" fontFamily="Georgia" id="lblArcWelcome" verticalAlign="middle" textAlign="center" horizontalCenter="2" includeIn="login" verticalCenter="116"/>
          <s:Label text="Please login with your Agent Account." fontSize="14" fontFamily="Georgia" textAlign="center" verticalAlign="middle" id="lblLoginMsg" horizontalCenter="-2" includeIn="login" verticalCenter="139"/>
          <s:Label text="Agent Account:" id="lblAcct" horizontalCenter="-108" includeIn="login" verticalCenter="183"/>
          <s:Label text="Password:" id="lblPwd" horizontalCenter="-121" includeIn="login" verticalCenter="209"/>
          <s:TextInput width="211" id="txtAcct" horizontalCenter="46" includeIn="login" verticalCenter="178"/>
          <s:TextInput width="211" id="txtPwd" horizontalCenter="46" includeIn="login" verticalCenter="208"/>
          <s:Button label="Login" id="btnLogin" horizontalCenter="2" includeIn="login" verticalCenter="253"/>
          <mx:Image source="assets/images/icons/Icon_Original.png" horizontalCenter="-4" top="10" width="500" includeIn="login" id="imgLogo"/>