Since a Android-looking popup box doesn't yet exist in the Hero SDK, I thought I would put a pretty good looking component together.
You can download it (and the sample code) here:
http://www.digitalretro.tv/components/InformationBoxTest.fxp
A real simple example in in the project, for both an Info and an Alert.
I currently only support an "OK" button, but I will be adding a Yes/No and OK/Cancel later this week.
Hopefully this will save someone some time.
Enjoy and feel free to use this in your code (commercial or non-commercial), just leave the copyright code in the component source file in place.
Thanks.
Darren
Here's an updated library. I changed it to MessageBox and uploaded a new Flex Project:
http://www.digitalretro.tv/components/MessageBoxText.fxp
This take the popup messages and adds an OK/CANCEL and a YES/NO option.
Enjoy.
Darren
Thanks for this! It looks great and saved me a ton of grief.
I wrote up a quick blog post about it, with an additional bit of code to auto set a default parent: http://mattguest.com/2010/12/air-for-android-alert-box-solution/
Thanks again!
Hi Adam.
You can import a FXP into FB.
Have a look here: http://help.adobe.com/en_US/flashbuilder/using/WSbde04e3d3e6474c4ef541 1412477fbf920-8000.html#WSbde04e3d3e6474c4-247dcc961226561b12d-7ffe
Since it's a little easier to work with, I compiled a SWC from the code, which can be downloaded here: http://dl.dropbox.com/u/3831772/adbe/AndroidAlerts.swc
Hm, actually I've just realized the images aren't included in the SWC, and I had to include them in my project to get them to show up. I've never built a SWC that includes images before, can it be done? How?
I tried to embed images and create a library but there is a bug in Flex Hero. I post my code here to let someone build it when it will be fixed.
http://dl.dropbox.com/u/22049158/MesssageBox-digitalRetro.fxpl
Hi.
I tried the Messagebox and it works great but is it possible to use a TextInput with it?
I added a Textinput and when i enter the Textinput i got an Focusmanager is null error:
private function touchMouseDownHandler(event:MouseEvent):void
{
isMouseDown = true;
mouseDownTarget = event.target as InteractiveObject;
// If we already have focus, make sure to open soft keyboard
// on mouse up
if (focusManager.getFocus() == this)
delaySetFocus = true;
// Wait for a mouseUp somewhere
systemManager.getSandboxRoot().addEventListener(
MouseEvent.MOUSE_UP, touchMouseUpHandler, false, 0, true);
systemManager.getSandboxRoot().addEventListener(
SandboxMouseEvent.MOUSE_UP_SOMEWHERE, touchMouseUpHandler, false, 0, true);
}
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at spark.components.supportClasses::SkinnableTextBase/touchMouseDownHandler()[E:\dev\hero_private\frameworks\projects\spark\src\spark\components\supportClasses\SkinnableTextBase.as:2140]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.managers::SystemManager/mouseEventHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\SystemManager.as:2924]
Does anyone tried to use a TextInput or Textarea?
I think it's the a problem with the Keyboard. Does mobile air can't use the "Android" Keyboard in Popup's?
I was going to ask if anyone had made a version that looks like the Gingerbread dialogs, but ultimately I think the onus is on the AIR development team to expose some API to us to create native dialogs, because we're now at the point where it's very possible that our applications will look outdated and disjointed for using a dialog style that doesn't match the system style. Native applications don't have this problem, which is a problem for us.
@Thomas_Ah: I never used ViewNavigatorApplication. The modifications steps you described don't compile for me. May you give us a project example?
The thing I made to use "alert and information popup boxes" is to add MessageBox component in my application (a MobileApplication) and then use it (or modify it). It would be greate to use it as an external library but it was not embedding assets because of a Flex Hero bug.
I hope this could help you.
@Adam.Tuttle: You are right, it would be usefull to have this native behavior but when you develop with an alternative framework, you could expect this problems.
Gingerbread dialogs could be reproduced by modifying "alert and information popup boxes" component's CSS. If you do so, please post your code here.
It's a bug : https://bugs.adobe.com/jira/browse/SDK-30384
Hi,
like i've posted here, I've compiled EhlersD's code into a library. Since Flex 4.5 has been released, my project has no more bug.
You can download the library here:
http://dl.dropbox.com/u/22049158/MesssageBox-digitalRetro.swc
Have fun ;-)
Hi,
Actually you use this component like every Flex component: just subscribe to the event by calling "addEventListener". There is 4 events (messageBoxOK, messageBoxCANCEL, messageBoxYES, messageBoxNO).
You should have something like this to use this component (not tested):
var msgBox:MessageBox = MessageBox.show(null, MessageBox.MB_OK, MessageBox.IC_HELP, "help box!", "show something helpfull");
msgBox.addEventListener(MessageBoxEvent.MESSAGEBOX_OK, myHandler);
Of course, you can use instanciate your component with MXML. I let you try it.
Thanks naelmskine. That helped me. But MessageBox.show(null.... using null gave me a null object runtime error. So I used the parent instead and it worked fine. However, I'm not sure if icons like MessageBox.IC_HELP, MessageBox.IC_DELETE, MessageBox.IC_ADD etc are in built. Because they doesn't seem to work. It always shows up some broken icon.
Hi megharajdeepak,
when i first tried to compile this component as a library i think i got this problem but it was a bug and Adobe fixed it. As I remember it was working with the SWC but you can simply copy this component in your project and it should avoid this problem.
I have no time to test it and fix the problem but here is the flash builder project: http://dl.dropbox.com/u/22049158/MesssageBox-digitalRetro.fxpl (if you have an other IDE just unzip it).
Feel free to modify this component but don't forget to share your code.
That's great! thanks again. Sure, I'll have a look at it ![]()
I am actually using this component for an ipad app. When I am in portrait mode and when I get this message and then when i tilt the device to landscape mode, the message box just stays where ever it was when the device was in portrait mode. I think, I need to listen for stage rotate events and position the x and y co ordinates of the message box based on the width, height and available space. But just wanted to know if there is any simple way already in the component to achieve this requirement, which I might be missing out?
Cheers!
Deepak
I made following changes to achieve it:
MessageBox.mxml:
Root Group's creationComplete event handler:
protected function group1_creationCompleteHandler(event:FlexEvent):void
{
if(stage.supportedOrientations)
{
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onDeviceOrientationChange);
}
}
private function onDeviceOrientationChange(event:StageOrientationEvent):void
{
if(this != null && stage != null)
{
this.x = stage.stageWidth/2 - this.width/2;
this.y = stage.stageHeight /2 - this.height/2;
}
}
With this, based on device rotation, the message box's x and y co-ordinates get set in such a way that box appears in the middle of the stage always. Hope this helps someone... ![]()
Cheers!
Deepak
North America
Europe, Middle East and Africa
Asia Pacific