Adobe AIR: Native Alerts using ANEs

For the current sample I have used the opensource ANE (Adobe Native Extension) from freshplanet (here is the github link).

I know there are many more other ANE’s but the reasons of using this one inside my sample project are:

  • Easy to setup
  • Callback functions
  • Option to show as an alert, or as a questionaire

Step 1: Checkout the project from Github, or just download the *master.zip from here.

Step 2: Create an /ane folder inside the root of your project and copy the native estension ( or just copy it the same foder with your other ANEs Рif already using any)

Step 3: Add the extension inside your project and be sure to check the options to include it for all “mobile” OS/s you are deploying your app (in our test we use both iOS and Android). To achieve that goto:

Project->Properties->Flex Build Path->Native Extensions [tab]->Click “Add Ane”-> Browse and select your AirAlert.ane
Project->Properties->Flex Build Packaging->Apple iOS/Google Android->Native extensions [tab]-> Check *package

See picture below…

Flex-Props-Add-Ane

extemsion pakage

 

 

 

 

Step 4: Call the extension to show some alerts and handle the results. ¬†see code below…


<fx:Script>
<![CDATA[
	import com.freshplanet.ane.AirAlert.AirAlert;
	
	private function onSimpleAlertClick():void
	{
		if(AirAlert.isSupported)
		{
			AirAlert.getInstance().showAlert("Alert", "This is a Simple Alert with string message");
		}
		else
		{
			trace("Aler not supported!");
		}
	}
	
	private function onYesNoAlertClick():void
	{
		if(AirAlert.isSupported)
		{
			AirAlert.getInstance().showAlert("Alert", "Are you sure ?", "Yes", yesAlertCallback, "No",noAlertCallback);
		}
		else
		{
			trace("Aler not supported!");
		}
	}
	
	private function yesAlertCallback():void
	{
		AirAlert.getInstance().showAlert("Answer","You selected 'Yes'");
	}
	
	private function noAlertCallback():void
	{
		AirAlert.getInstance().showAlert("Answer","You selected 'No'");
	}
	
]]>
</fx:Script>
	
<s:VGroup
	width			= "100%"
	height			= "100%"
	horizontalAlign	= "center"
	verticalAlign	= "middle">
	
	<s:Button 
		label		= "Simple Alert"
		click		= "onSimpleAlertClick()"/>
		
	<s:Button 
		label		= "Yes/No Alert"
		click		= "onYesNoAlertClick()"/>
</s:VGroup>

Leave a Reply


8 − two =