Hey all,
I am trying to create a custom component by extending the
UIComponent class [ AS3 only ] . I followed it pretty much from the
documents on flex.org. But here is the wierd part. If I add the component
using just mxml it works fine
traces out the statement in the constructor , shows the component. But if I
create the component using just as3 then it doest call the constructor.
Further more if I add the component it goes into a infinite loop.
cheers :)
firdosh
//MAIN MXML CLASS
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="init(event);" xmlns:FComponents="org.fcomponents.*">
<mx:Script>
<![CDATA[
import org.fcomponents.Test;
import mx.containers.Panel;
import org.fcomponents.NumericSlider;
import flash.events.Event;
private function init(evt:Event):void{
trace("add");
var c:NumericSlider=new NumericSlider();
trace("call");
//addChild(c); // UNCOMMENT THIS FOR INFINITE LOOP
//this.addChild(new NumericSlider());
//<FComponents:NumericSlider /> IF YOU ADD THIS STATETMENT
BELOW IT WORKS FINE
}
]]>
</mx:Script>
</mx:Application>
//CUSTOM COMPONENT CLASS
package org.fcomponents
{
import mx.core.UIComponent;
import mx.controls.Button;
import mx.controls.VSlider;
import mx.controls.NumericStepper;
import flash.events.Event;
[Event (name="change" ,type="flash.events.Event") ]
public class NumericSlider extends UIComponent
{
private var $stepper:NumericStepper;
private var $slider:VSlider;
private var $showSlider:Button;
private var $valueChanged:Boolean;
private var $value:Number=0;
public function NumericSlider(){
super();
trace("NS Constructor");
$valueChanged=false;
}
override protected function createChildren():void{
super.createChildren();
if(!$stepper){
$stepper=new NumericStepper();
addChild($stepper);
}
}
override protected function commitProperties():void{
super.commitProperties();
if($valueChanged){
$valueChanged=false;
$stepper.value=$value;
invalidateDisplayList();
}
}
override protected function measure():void{
super.measure();
$stepper.width=100;
$stepper.height=22;
}
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth,unscaledHeight);
}
}
}