How to delete an item from item renderer in Spark List Flex/AIR?

	
<s:ItemRenderer>
	<fx:Script>
		<![CDATA[
			import spark.components.List;
			
			public function deleteItem():void 
			{
				var parentList:List = owner as List;
				
				parentList.dataProvider.removeItemAt(parentList.dataProvider.getItemIndex(data))
			}
		]]>
	</fx:Script>
	<s:HGroup>
		<s:Label text="{data}" />
		<s:Button id="remove" label="X" click="deleteItem()"/>
	</s:HGroup>
</s:ItemRenderer>
Advertisements

Static initalizer in Actionscript 3


Static initalizer
--------------------
package
{
 public class MyStaticClass
 {
 // This is the static initializer
 {
 trace("Running static initilizer!");
 staticInitializer();
 }

// We're calling a secondary method so we can use local variables
 static private function staticInitializer():void
 {
 var now:Date = new Date;
 baseColor = now.hours > 16 ? 0x000066 : 0x0000FF;
 }

static public var baseColor:uint;
 }
}

Make object as Bindable in Flex/AIR

Try use ObjectProxy instead of Object.

[Bindable]
private var registerProxy:ObjectProxy = new ObjectProxy();

public function setDP():void{
	
	registerProxy.firstName = 'Raja';
	registerProxy.middleName ='Kumar'
	registerProxy.lastName = 'King'
	registerProxy.email = 'rajaj@sybrant.com';
	registerProxy.password = 'pwd';
	registerProxy.confirmPassword = 'pwd';
}

public function dataUpdateHandler(event:Event, property:String, typeString:String):void
{
	if(!registerProxy.hasOwnProperty(property))
	{
		Alert.show('registerProxy doesn\'t contains property' + property);
		return;
	}
	
	switch (typeString.toLowerCase())
	{
		case 'textinput':registerProxy[property] =((event.currentTarget as TextInput).text);break;
		case 'textarea':registerProxy[property] =((event.currentTarget as TextArea).text);break;
		case 'dropdownlist':registerProxy[property] =((event.currentTarget as DropDownList).selectedItem);break;
		case 'checkbox':registerProxy[property] =((event.currentTarget as CheckBox).selected.toString());break;
		case 'numstepper':registerProxy[property] =((event.currentTarget as NumericStepper).value.toString());break;
	}
}

<s:Form>
	<s:FormItem label="First Name" skinClass="MyFormItemSkin">
		<s:TextInput text="{registerProxy.firstName}" change="dataUpdateHandler(event,'firstName','textinput')"/>
	</s:FormItem>
	<s:FormItem label="Middle Name" skinClass="MyFormItemSkin">
		<s:TextInput text="{registerProxy.middleName}" change="dataUpdateHandler(event,'middleName','textinput')"/>
	</s:FormItem>
	<s:FormItem label="Last Name" skinClass="MyFormItemSkin">
		<s:TextInput text="{registerProxy.lastName}" change="dataUpdateHandler(event,'lastName','textinput')"/>
		<s:TextInput text="{registerProxy.email}" change="dataUpdateHandler(event,'email','textinput')"/>
	</s:FormItem>
	<s:FormItem label="Password">
		<s:TextInput text="{registerProxy.password}" change="dataUpdateHandler(event,'password','textinput')"/>
	</s:FormItem>
</s:Form>

Using constant in Flex CSS – with complie time error checking ?



s|TextArea{
 color:#eeeeee;
}

s|Button{
 color:#eeeeee; /* the same color as above*/
}
/* file: style\StyleConstants.as */
private const someColorConstant:uint = 0xff0000;
/* file: style\Style.css */
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";

s|TextArea{
 color:PropertyReference("someColorConstant");
}

s|Button{
 color:PropertyReference("someColorConstant");
}

 


<?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" >

<!-- // STYLE -->
 <fx:Style source="style/style.css" />
 <fx:Script>
 <![CDATA[
 include "style/StyleConstants.as";
 ]]>
 </fx:Script>
 <!-- // STYLE END -->

<s:Button x="10" y="10" label="Some button"/>
 <s:TextArea x="100" y="10" text="Some text"/>

</s:Application>


src : http://robertbak.com/wordpress/2011/10/using-constants-in-flex-css-with-compile-time-error-checking/