I'm working on a project with Actionscript 3.0 in Flash Pro (CS5). I want to create a confirmation box. If I were using the Flex SDK I could do this using the Alert class in the mx.controls package. However, it seems that no similar control exists in the standard Flash library and any amount of Googling just leads me to Flex references.
-
1You sound confused. All Flex controls are built off ActionScript 3 and do not work in ActionScript 2 projects. The mx.controls.Alert class is part of the Flex Framework and therefore ActionScript 3. You never used that in an ActionScript 2 project. – JeffryHouser Oct 29 '11 at 15:35
-
I understand what he means since I have the same problem. In pure AS3 project mx.controls.Alert doesn't exist (but it does for a Flex project). I supposed it used to exist in AS2. – ADB Nov 05 '11 at 16:47
4 Answers
Try this Class
package com.whatever {
//Imports
import flash.display.Shape;
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.events.MouseEvent;
//Class
public class AlertBox extends Sprite {
//Vars
protected var box:Shape;
protected var yesBtn:Sprite;
//Constructor
public function AlertBox($:Rectangle):void {
//Initialise
box = new Shape()
yesBtn = new Sprite()
addChild(box)
addChild(yesBtn)
//Render
with (box.graphics) {
lineStyle(1)
beginFill(0, 0.4)
drawRect($.x, $.y, $.width, $.height)
endFill()
}
with (yesBtn.graphics) {
lineStyle(1, 0x00FF00)
beginFill(0x00FF00, 0.4)
drawRect($.x+$.width-100, $.y$.height-40, 80, 20)
endFill()
}
//Events
yesBtn.addEventListener(MouseEvent.CLICK, yesClickHandler, false, 0, true)
yesBtn.addEventListener(MouseEvent.MOUSE_OVER, yesOverHandler, false, 0, true)
}
//Handlers
protected function yesClickHandler($):void {}
protected function yesOverHandler($):void {}

- 1,862
- 9
- 39
- 75
You said that you can't import mx.Controls in AS3 but the following should work in a flex 4 project:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function init():void
{
Alert.show("This is an Alert!!!");
}// end function
]]>
</fx:Script>
</s:Application>
[UPDATE]
After realizing that I misunderstood the question, I looked on the internet for a Alert component for AS3 projects and found the following:
http://developer.yahoo.com/flash/astra-flash/alertmanager/
I'm going try my hand at creating a replica of the flex framework's Alert control and then update my answer again.

- 3,209
- 2
- 17
- 15
-
i didnt use .mxml file,i used .fla file so i Cannot import mx Controls in as3 – Mercy Oct 29 '11 at 11:42
-
@LeemaRose ah you want to use the Alert controls in a pure as3 project. Ok, give me a chance to change my answer. – Taurayi Oct 29 '11 at 11:46
-
i already saw that example and also i tried but i Cannot import com.yahoo.astra.fl.managers.AlertManager; – Mercy Oct 29 '11 at 12:18
-
@Leema Rose did you copy the AlertManager component from the library of the downloadable [fla](http://developer.yahoo.com/flash/astra-flash/alertmanager/examples/SimpleASAlert.fla) to your fla's library? – Taurayi Oct 29 '11 at 12:52
-
If i Download and run the program it's working sir,but Seperately i cannot import com.yahoo.astra.fl.managers.AlertManager sir – Mercy Oct 29 '11 at 14:18
-
@Leema Rose but did you copy the AlertManager component from the downloaded fla's library into your fla's library? If you don't know how, I can take screenshots of it and update my answer, but it's pretty simple. – Taurayi Oct 29 '11 at 15:59
If your final swf is going to run in the browser and have script access, you could just use one of the JavaScript PopUp Boxes:
if(ExternalInterface.available) {
if (ExternalInterface.call("confirm", "Should I trace 'Yes'?")) {
trace("Yes"); // user clicked Okay
} else {
trace("User canceled or the call failed");
}
}
I'm pretty sure this will freeze the Flash UI loop until the JavaScript function returns, so make sure you call it when it's all you want to be doing.

- 67,214
- 13
- 180
- 245
I believe that you can continue to use the same Alert class
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Alert.html