Tag Archives: Mx

Adding Links in Menu in Adobe AIR/ FLEX.

Hi all…

In this tutorial I will show you how to add links in a menu in Adobe AIR/ FLEX.
It is really simple. Just add a normal menu item and on the click handler for menu items match the label and navigate to the URL, that’s all.
Check out this example.
Change the mx:Application to mx:windowedApplication to work this example as AIR application.



	
		
					
						
						
					
					
						
					
				;

			// create menu items
			private function init():void {
				menuCollection = new XMLListCollection(menubarXML);
			}

			// click handler for menubar
			private function menuHandler(event:MenuEvent):void
			 {
				if(event.item.@label=="Google.com")
				{
					var url:URLRequest = new URLRequest('http://www.google.com');
					navigateToURL(url,'_parent');
				}
				else if(event.item.@label=="Yahoo.com")
				{
					url = new URLRequest('http://www.yahoo.com');
					navigateToURL(url,'_parent');
				}
			}
		]]>
	
	
	
	

Link in menu example in Adobe AIR

How will you access the clipboard in an AIR application?

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.");
                  }
            }
      ]]>

How do you call an actionscript function from a html page and viceversa. How to you access the actionscript variable function from an HTML page in actionscript.

The following code helps you to do this.
Save the following  code as am .mxml file

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="init()">
    <mx:Script>
    <![CDATA[
        private var calledFromJSHandlerFunction:Function = calledFromJSHandler;
        private function init():void{
            html.addEventListener(Event.HTML_DOM_INITIALIZE, domInitialized);
            html.location = "start.html";
        }
        private function domInitialized(event:Event):void{
            html.htmlLoader.window.calledFromJSHandlerFunction = calledFromJSHandlerFunction;
        }
        private function calledFromJSHandler():void {
            mx.controls.Alert.show("ActionScript called from JavaScript", "Alert");
        }
        private function doHTMLAlert( ):void {
            html.htmlLoader.window.calledFromAS();
        }
    ]]>
    </mx:Script>
    <mx:Button id="alertBtn" label="Call JavaScript from ActionScript"
        click="doHTMLAlert()" x="137" y="10"/>
    <mx:HTML id="html" x="137" y="40" width="339"/>
    <mx:Label x="10" y="12" text="Normal MXML Button"/>
    <mx:Label x="28" y="38" text="HTML component"/>
</mx:WindowedApplication>

The html file start.html

<html>
    <script language="Javascript">
        function calledFromAS() {
            alert('Hello from ActionScript');
        }
        </script>
    <body>
        <input type="button"
            value="Call ActionScript from JavaScript"
            onclick="calledFromJSHandlerFunction()" />
        <br />
        <input type="button"
            value="Normal JavaScriptAlert"
            onclick="alert('Hello from JavaScript')">
    </body>
</html>