How will you access the clipboard in an AIR application?

By | January 15, 2011

The following is a sample code to do this.
Simply copy and paste.

<xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">

            public function init():void{
                  var str : String = "Hello";
                  System.setClipboard(str);

                  var versionString:String = Capabilities.version;
                  var pattern:RegExp = /^(w*) (d*),(d*),(d*),(d*)$/;
                  var result:Object = pattern.exec(versionString);
                  if (result != null)
                  {
                        trace("input: " + result.input);
                        trace("platform: " + result[1]);
                        trace("majorVersion: " + result[2]);
                        trace("minorVersion: " + result[3]);
                        trace("buildNumber: " + result[4]);
                        trace("internalBuildNumber: " + result[5]);
                        trace("MP3 playBack : " + Capabilities.hasMP3);
                        trace("Res  X "+ Capabilities.screenResolutionX);
                        trace("Res  Y "+ Capabilities.screenResolutionY);
                        trace(" IME Installed " + Capabilities.hasIME);

                        if (Capabilities.hasIME)
                        {
                              if (IME.enabled)
                              {
                              trace("IME is installed and enabled.");
                              }
                              else
                              {
                              trace("IME is installed but not enabled. Please enable your IME and try again.");
                              }
                        }
                        else
                        {
                              trace("IME is not installed. Please install an IME and try again.");
                        }
                  }
                  else
                  {
                        trace("Unable to match RegExp.");
                  }
                  if (Capabilities.hasIME)
                  {
                        switch (IME.conversionMode)
                        {
                        case IMEConversionMode.ALPHANUMERIC_FULL:
                        trace("Current conversion mode is alphanumeric (full-width).");
                        break;

                        case IMEConversionMode.ALPHANUMERIC_HALF:
                        trace("Current conversion mode is alphanumeric (half-width).");
                        break;
                        case IMEConversionMode.CHINESE:
                        trace( "Current conversion mode is Chinese.");
                        break;
                        case IMEConversionMode.JAPANESE_HIRAGANA:
                        trace( "Current conversion mode is Japananese Hiragana.");
                        break;
                        case IMEConversionMode.JAPANESE_KATAKANA_FULL:
                        trace( "Current conversion mode is Japanese Katakana (full-width).");
                        break;
                        case IMEConversionMode.JAPANESE_KATAKANA_HALF:
                        trace( "Current conversion mode is Japanese Katakana (half-width).");
                        break;
                        case IMEConversionMode.KOREAN:
                        trace( "Current conversion mode is Korean.");
                        break;
                        default:
                        trace("Current conversion mode is " + IME.conversionMode + ".");
                        break;
                        }
                  }
                  else
                  {
                        trace("Please install an IME and try again.");
                  }
            }
      ]]>

Leave a Reply

Your email address will not be published.