AS3 NATIVE ALERT- Android / IOS / Windows

Update: fixed iOS air 3.2 bug

Got a new device. The Lenovo Thinkpad Tablet and with that the app that I’m working on requires some changes.
I’v added support for Android in my NativeAlert Extension.
Not only it’s a plain alert that pops out over the Adobe AIR content but it also has the ability to change themes. This is quite important in my work because I have not decided how will the application look like.

Grab the source from github:

Available themes for android:


Usage: "some message" , "title" , "first button label" , "otherButtons,LabelsSeperated,WithAComma" , someAnswerFunction , themesForThisAlert);

Also added a function for setting default theme:

NativeAlert.defaultAndroidTheme = NativeAlert.THEME_DEVICE_DEFAULT_DARK;

35 thoughts on “AS3 NATIVE ALERT- Android / IOS / Windows

  1. fukhaos says:

    How I use that in Flash CS5.5, sdk 3 ?

    My app is for ios ?

    • There is a nice tutorial from iBrent :
      But mainly what you want to do is to download the zip from git and there is a file NativeAlert.ane in the bin/release folder and rename it to NativeAlert.swc.
      Simply add it to flash as a normal library but remember to mark it as an external library , and You are ready to go.
      Just import the package: pl.mateuszmackowiak.nativeANE.alert.NativeAlert.

  2. darkredz says:

    hi, it seems that the ane does not work in android gingerbread but works fine on android ics.

    • Ok. Fixed it I think? Don’t have a 2.3 device and the code was compiled in 3.1.
      The themes ware introduced in the 11 revision of the sdk.
      Hope it works. Let me know.

      • darkredz says:

        it works on android 2.3 now. The alert is shown correctly but after a few seconds the Air app will crash (the application xxxx has stopped unexpectedly error).

        My usage in code is without NativeAlert.defaultAndroidTheme: msg , title , b1);

      • Must say that not having those devices is problematic :/
        Try this it now. I’v put everything in try catch block so nothing should pass by without any answer. If there is a problem should trace out if You are debugging it.

      • darkredz says:

        great it actually works without crashing now on android 2.3

      • Great! Hope the rest works on 2.3 not just the “NativeAlert” class.
        I try to fix the iOS as soon as possible. Thanks for the comment

      • darkredz says:

        yes the others like Toast and stuffs work on 2.3, tried with the demo apk. Just that nativealert has some problem previously. You might wanna update the demo app APK

  3. darkredz says:

    Oh will try the fix for android 2.3 again. Btw, I realized that the alerts works in IOS 5 but not in IOS 4.3, seems that it will crash the app before any alert can be shown

    • Don’t really know about IOS right now because I don’t have my MAC until the end of the next month.
      For now the IOS side is based on the ones from liquid-photo.
      But if I get back My MAC promise to look at it.

  4. ouija board says:

    i love your blog, i have it in my rss reader and always like new things coming up from it.

  5. how can i get taller says:

    I truly do have confidence in every one of the methods you’ve got shown to this page. They may be incredibly convincing and can absolutely function. Nonetheless, the particular blogposts are far too quick firstly. May possibly an individual remember to extend all of them just a little coming from next occasion? Thanks for the article.

  6. Juan says:

    Hi Mateus, i am looking like a crazy man some extension to create Local Notifications like Native local notification in IOS:

    it’s posible to create Local Notification with your extension? Any help?

    Thanks for sharing…too much ;)

    • Hi,
      what’s wrong with the one on the adobe site:
      I tested it once and seem to work.
      I can try to do something different bo no quit now.

      • Juan says:

        Thanks for answer!, the adobe extension doesn’t allow scheduled messages, and AIR application can’t run in IOS background, therefore, adobe extension doesn’t have much sense in IOS :(, with this extension, is impossible create a app reminder or something like that.

      • Ok, Your right. It does not fire if its in the background. Hmm than I wander what was it for?
        Nevermind that. I think I can do that but it will take me some time because I’m pretty busy but maybe can figure something out.
        But until that maby You can try it Yourself.
        Basicly all You need is:

          - (IBAction)addNotification:(id)sender {
            UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object
            [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:[datePicker countDownDuration]]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer
            [localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert
            [localNotification setAlertBody:[alertBodyField text]]; //Set the message in the notification from the textField's text
            [localNotification setHasAction: YES]; //Set that pushing the button will launch the application
            [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1
            [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
            [localNotification release];
            [alertNotification setHidden:NO]; //Set the alertNotification to be shown showing the user that the application has registered the local notification
  7. Juan says:

    Thanks Mateus, I will try!, I will keep in contact.

  8. how I know what button was press in someAnswerFunction() ???

    • someAnswerFunction is a event handler function for the NativeAlertEvent. One of the parameters of this event is index. The index is the number of the button clicked.

      • Vinicius Oliveira says:

        Something like this?
        private function someAnswerFunction(index:int){

  9. More like:
    private function someAnswerFunction(event:NativeExtensionEvent):void{

  10. Vinicius Oliveira says:

    And how I make a alert with only button, because I left the otheButtons option with on a “”
    and show for me a second empty button

  11. fukhaos says:

    I just use:;

    and show 2 buttons: one write “OK” and other empty.

  12. fukhaos says:

    I will try !!

  13. Pervez alam says:


    I have tried Native Alert. It doesn’t work with android 2.2 though it works 2.3 onward.

  14. patrocle says:

    tried with AIR3.3 on ios, works perfectly exept once a button is cliqued, the application loose focus, it’s not freeze (fps 60 and animations running), it’s just you can’t click on anything anymore, even if you call the dispose function. Like if a blank layer was on top of the app…

  15. Sander says:

    Hey and thanks for the extension.

    So far i have used your source, compiled new ane file. But i keep getting this error:
    [StatusEvent type=”status” bubbles=false cancelable=false eventPhase=2 code=”error” level=”-1″]

    I have not modified anything, just recompiled from your source, and when i try to run it on android, it will close the app, with no message.

    My main goal is to modify your alert ane to show “SpannableString” with “linkify” in the message instead of simple String. But if i cant get the original source working i cant have a lot of hope with modified one.

    Thanks in advance!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: