Skip to content


Checkbox Component

A little piece that utilized the Checkbox component, Button component, and Yahoo!’s Alert Manager component. Things like this are probably more appropriate for Flex and MXML, but for now I will stick with CS3.

package
{
	// Components Used:
	// --------------------
	// Yahoo! Alert Manager
	// Button
	// CheckBox

	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import com.yahoo.astra.fl.managers.AlertManager;
	import fl.controls.Button;
	import fl.controls.CheckBox;

	public class Main extends Sprite
	{
		private var cb:CheckBox;
		private var cb2:CheckBox;
		private var checkBoxStatus:String = "";
		private var cbArr:Array;

		public function Main()
		{
			// CHECK BOX 1
			cb = new CheckBox();
			cb.label = "Checkbox 1";
			cb.x = 10;
			cb.y = 10;

			cb.addEventListener ( MouseEvent.CLICK, alertCheck );

			addChild ( cb );

			// CHECK BOX 2
			cb2 = new CheckBox();
			cb2.label = "Checkbox 2";
			cb2.x = 100;
			cb2.y = 10;

			cb2.addEventListener ( MouseEvent.CLICK, alertCheck );

			addChild ( cb2 );

			// NEW BUTTON
			var button:Button = new Button();
            button.width = 150;
            button.height = 30;
            button.move ( stage.stageWidth / 2 - button.width / 2, stage.stageHeight / 2 - button.height / 2 );
            button.label = "Check Checkboxes";  

            addChild(button);  

            button.addEventListener(MouseEvent.CLICK, alert);
		}

		//event handler to trigger the alert
       	function alert(m:MouseEvent):void
		{
			cbArr = new Array();

			if ( cb.selected ) cbArr.push ( cb.label );

			if ( cb2.selected ) cbArr.push ( cb2.label );

			if ( cbArr.length > 0 )
			{
				checkBoxStatus = "Checked Boxes: " + cbArr;
			}
			else
			{
				checkBoxStatus = "No checkbox values found.";
			}

			AlertManager.createAlert(this, checkBoxStatus, "ALL CHECKBOXES",["close alert"]);
		}

		function alertCheck (m:MouseEvent)
		{
			AlertManager.createAlert(this, m.currentTarget.label + " was checked - the value is: " + m.currentTarget.selected, "Checkbox Status",["close alert"]);
		}
	}
}

Posted in Actionscript 3, Flash Components.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Geoff says

    Perfect example. Exactly what I was looking for and yes, applicable to my Flex development. Much appreciated.



Some HTML is OK

or, reply to this post via trackback.