PDA

View Full Version : How to properly extend the CS3 components



glidealong
January 3rd, 2008, 07:16 AM
It's been quite a while since i have started trying to inherit a cs3 component to build a custom component for my applications. And all the attempts had ended with building the components based on composition rather than inheritance. I have achieved quite satisfactory results with composition technique, but I'm still not sure whether it's possible to customize the cs3 component using inheritance rather than composition.

My code for the futile attempts start with


package script.primitives{

import fl.core.UIComponent;
import fl.controls.ComboBox;
public dynamic class DropDown extends ComboBox {
public function DropDown() {
super();
}
override protected function configUI():void {
super.configUI();
}
}

}


Is it right? And if yes how could i successfully put my dropdown instance on to stage???

Thanks a ton

trifox
January 3rd, 2008, 08:41 AM
It's been quite a while since i have started trying to inherit a cs3 component to build a custom component for my applications. And all the attempts had ended with building the components based on composition rather than inheritance. I have achieved quite satisfactory results with composition technique, but I'm still not sure whether it's possible to customize the cs3 component using inheritance rather than composition.

My code for the futile attempts start with


package script.primitives{

import fl.core.UIComponent;
import fl.controls.ComboBox;
public dynamic class DropDown extends ComboBox {
public function DropDown() {
super();
}
override protected function configUI():void {
super.configUI();
}
}

}
Is it right? And if yes how could i successfully put my dropdown instance on to stage???

Thanks a ton

it is as simple as it might be ;) just use it in your mxml document like this


<?xml version="1.0"?>
<!-- Simple example to demonstrate the ComboBox control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:mynamespace="yourclasspath.*">
<mynamespace:DropDown />

</mx:Application>
if not using mxml, but as3 you do it like this, inside any UIComponent/DisplayObject

x:ComboBox=new ComboBox()
addChild(x);

glidealong
January 4th, 2008, 01:57 AM
it is as simple as it might be ;) just use it in your mxml document like this

f not using mxml, but as3 you do it like this, inside any UIComponent/DisplayObject

x:ComboBox=new ComboBox()
addChild(x);

Yeah I am using as3 only in Flash CS3. But if my understanding is correct the above code equates to composition rather than inheritance. It is similar to what I had been doing so far. My efforts are to find out if I can use just inheritance without any addchild() command to put the cs3 component on to stage.

Hope I have made myself clear..

Thanks trifox

glidealong
January 4th, 2008, 07:03 AM
so far i've been able to extend combobox to create a dropdown class and i was able to add it to stage by


import script.primitives.DropDown;
import fl.data.DataProvider;
var dd:DropDown = new DropDown();
dd.x = 100;
dd.y = 100;
var dp:DataProvider = new DataProvider();
dp.addItem({label:"Item 1"});
dp.addItem({label:"Item 2"});
dp.addItem({label:"Item 3"});
dp.addItem({label:"Item 4"});
dd.skin = "dropdownskin.swf";
dd.skinBackgroundColor = 0x666666;
dd.dataProvider = dp;
addChild(dd);
The major problem is that i dont see any skin applied on the component. rather this generates a text filed with contents 'Item 1' which is obviously the first object in the dataprovider that I provided to the dropdown instance. It's neither selectable or editable. How to apply a skin to this custom component?

Another problem is that when i look at the compiled clip it's an empty clip. ie when you drag and drop the compiled clip on to stage you see nothing!!!!!.. i would like to have this component drag and drop from the library to the stage rather than using addchild(). ??

Will let you know if I could achieve what i intend to..

audiohominis
November 19th, 2008, 11:44 PM
That makes two of us.

Glad to know I'm not the only one struggling with extending components. Even though you didn't get it to work as desired, you're still way ahead of me on this one.
Question: When you add multiple instances of your extended ComboBox, is the tab indexing maintained or did it go bye bye, 'cause I couldn't keep the focus order in mine.