View Full Version : Create Repeater in ActionScript
angie
05-22-2008, 12:39 PM
Does anybody know how to create a Repeater in ActionScript rather than MXML? I am using the following code but I can't seem to get the child descriptors to work. Thanks.
var a:Array = new Array();
a.push({label:"A", data:"a"});
a.push({label:"B", data:"b"});
a.push({label:"C", data:"c"});
var rep2:Repeater = new Repeater();
rep2.dataProvider = a;
var cd:Array = new Array();
cd.push(new mx.core.UIComponentDescriptor({type: mx.controls.Button}));
rep2.childDescriptors = cd;
addChild(rep2);
angie
05-22-2008, 02:32 PM
Got it, I was missing the following call...
rep2.initializeRepeater(this,true);
Also, not much information about this out there so thought I'd include an example of setting properties on the UIComponentDescriptor also...
cd.push(new mx.core.UIComponentDescriptor({type: mx.controls.Button, propertiesFactory:function():Object { return {label: "Dynamic",width: 300}}}));
Durai_ram
02-25-2009, 09:20 AM
It's possible to add image & label with repeater using AS3.... How ? Give any reference or code.........
Thanx.
meven
06-10-2010, 06:35 PM
Hi,
I am getting an error of “Error #1007: Instantiation attempted on a non-constructor." for the following code. the repeater is unable to repeat the custom component.
wRepeater = new Repeater();
var descProps:Object = {};
descProps.type = recData;
descProps.document = this;
descProps.propertiesFactory = function():Object{return {infoData: wRepeater.currentItem}};
var recordDescriptor:UIComponentDescriptor = new UIComponentDescriptor(descProps as RecordDataComp);
acData = createRecordData(featureSet); //this returns as an array collection after an rest based service call.
wRepeater.dataProvider = acData;
wRepeater.childDescriptors = [recordDescriptor];
wRepeater.initializeRepeater(vBox2, true); // At this point I am getting the above said error.
vBox1.addChild(wRepeater);
Here ‘RecordDataComp’ is the custom component made up with VBox consisting an two text components in another VBox.
‘acData’ is ArrayCollection
‘infoData’ is the public property in ‘RecordDataComp’ actionscript class.
‘recData’ is the instance of ‘RecordDataComp’
‘wRepeater’ is the instance of ‘Repeater’
Any help would be appreciated.
Thanks in advance.
-Ven.
drkstr
06-10-2010, 07:07 PM
Repeaters are just a convienience class for defining looped elements in MXML.
If you are already using Actionscript, then it's better to just use the more efficient AS methods, IMHO.
IE. Define a loop, instantiate your object, and add it to the stage.
meven
06-18-2010, 01:33 AM
Repeaters are just a convienience class for defining looped elements in MXML.
If you are already using Actionscript, then it's better to just use the more efficient AS methods, IMHO.
IE. Define a loop, instantiate your object, and add it to the stage.
Hi,
Many thanks for looking into my code..
I some how got resolved the issue that I am getting.. But, custom components are not displayed in the 'vBox2'. Any help please..?
Thanks
-Ven.
drkstr
06-18-2010, 07:33 PM
Post your code.
meven
06-19-2010, 01:00 AM
Post your code.
Thanks for replying me back so soon.. Here is my sample code which is exactely same as in my project.
===========
MyMain.mxml file.
===========
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="l"
verticalAlign="middle"
xmlns:comps = "com.repcomp.*"
layout="vertical">
<comps:MyRepComp1/>
</mx:Application>
=============
MyRepComp1.as
=============
package com.repcomp
{
import com.repcomp.btnlbl.*;
import mx.containers.Canvas;
import mx.containers.VBox;
import mx.core.Repeater;
import mx.core.UIComponentDescriptor;
public class MyRepComp1 extends Canvas
{
private var rep2:Repeater;
private var vBox:VBox
[Bindable]
private var myArr:Array;
public function MyRepComp1()
{
super();
myArr = new Array();
myArr.push({label:"AAA", data:"aaa"});
myArr.push({label:"BBB", data:"bbb"});
myArr.push({label:"CCC", data:"ccc"});
vBox = new VBox();
vBox.setStyle("horizontalGap",60);
addChild(vBox);
var descProps:Object = {};
descProps.type = BtnLblComp1;//custom component.
descProps.document = this;
descProps.propertiesFactory = buttonPropFact;
var buttonDescriptor:UIComponentDescriptor = new UIComponentDescriptor(descProps);
rep2 = new Repeater();
rep2.dataProvider = myArr;
rep2.childDescriptors = [buttonDescriptor];
rep2.initializeRepeater(vBox,true);
addChild(rep2);
}
public function buttonPropFact():Object
{
var obj:Object = {};
//obj.label = rep2.currentItem.label;
obj.inData = rep2.currentItem;
return obj;
}
}
}
==============
BtnLblComp1.as
==============
package com.repcomp.btnlbl
{
import flash.events.MouseEvent;
import mx.containers.HBox;
import mx.containers.VBox;
import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.Label;
public class BtnLblComp1 extends HBox
{
[Bindable]
private var _inData:Object;
[Bindable]
private var _btnText:String;
[Bindable]
private var _lblText:String;
private var myBtn1:Button;
private var myLbl1:Label;
private var myVBx1:VBox;
public function BtnLblComp1()
{
super();
percentHeight = 100;
percentWidth = 100;
myVBx1 = new VBox();
myVBx1.percentWidth = 90;
myVBx1.percentHeight = 90;
myLbl1 = new Label();
myLbl1.width = 40;
myLbl1.height = 20;
myLbl1.text = lblText;
myVBx1.addChild(myLbl1);
myBtn1 = new Button();
myBtn1.width = 60;
myBtn1.height = 30;
myBtn1.label = btnText;
myVBx1.addChild(myBtn1);
myVBx1.addEventListener(MouseEvent.CLICK, clickBtn);
addChild(myVBx1);
}
public function clickBtn(evt:MouseEvent):void
{
Alert.show(evt.currentTarget.data,evt.currentTarge t.label);
}
public function get inData():Object
{
return _inData;
}
public function set inData(idt:Object):void
{
_inData = idt;
lblText = inData.data;
btnText = inData.label;
}
public function set btnText(btxt:String):void
{
_btnText = btxt;
}
public function get btnText():String
{
return _btnText;
}
public function set lblText(ltxt:String):void
{
_lblText = ltxt;
}
public function get lblText():String
{
return _lblText;
}
}
}
'label' and 'data' is not populating on 'Button' and 'Label' controls.. only empty buttons got
populated without labels. If you click on the button.. getting alerts.. but notting displayed in it.
Kindly have a look.
So Many thanks.
-Ven.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.