Home » ActionScript 3.0, Flash CS4

Free AS3 Checkbox Component:

15 March 2010 No Comment

Writing new stylesheet or editing the V2 is headache for me. So I have created my own checkbox component. Hope will help you in your projects.

Difficulty of Use:
Intermediate to advanced users.

Sample component1:

Code for Sample1:

import com.Designscripting.Components.ICheck;

	var _icheck:CheckButton = new CheckButton();
		_icheck.index = 1;
		_icheck.x = _icheck.y = 60;
		_icheck._txt.text = "SampleData 1";
		_icheck._btn.addEventListener(MouseEvent.CLICK, buttonClicked);
		addChild(_icheck);

function buttonClicked(e:MouseEvent):void
{
	//Code to open URL in _blank window.
	navigateToURL( new URLRequest("http://www.designscripting.com/"), "_blank");
	ICheck.setItem(e.target.parent);
}

Here we are importing the custom classes and creating an instance for CheckButton and adding it to display list.
Later on selecting the checkbox we are launching the URL:designscripting.com

Some Useful Functions of the Component:

  • setItem()
  • getSelectedIndices()
  • getSelectedData()
  • isItemSelected()

setItem: Static method to set the checkbox item selected.

getSelectedIndices: Static method to return selected index of checkbox, return type Array.

getSelectedData: Static method to return selected data of checkbox, return type Array.

isItemSelected: Static method to return checkbox is selected or not. return type Boolean.

Sample Component 2:

Code for Sample2:

import com.Designscripting.Components.ICheck;

var verticalSpacing:Number = 50;

for(var count:int =0; count<3; count++)
{
	var _icheck:CheckButton = new CheckButton();
	_icheck.x = 40
	_icheck.y = 70+count*verticalSpacing;
	_icheck.index = count;
	_icheck._txt.text = "SampleData "+count;
	_icheck._btn.addEventListener(MouseEvent.CLICK, buttonClicked);
	addChild(_icheck);
}

function buttonClicked(e:MouseEvent):void
{
	ICheck.setItem(e.target.parent);
}
resultMc.buttonMode = clearMc.buttonMode = true;
resultMc.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){
	_resultTxt.text = String("Selected Item\n"+ICheck.getSelectedIndices())
	trace(ICheck.getSelectedData())
	})
clearMc.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){ICheck.reset();_resultTxt.text = ""})

Find the source files attached.

VN:F [1.7.7_1013]
Rating: 0.0/10 (0 votes cast)
VN:F [1.7.7_1013]
Rating: 0 (from 0 votes)
Translate this post
        
        
        
        
  

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.