Got the solution for this problem with the help of using the flag
value.I just took a flag value as 0 by default and changing the flag
value when there is a setter (set data) has the value by checking like
public function set data(value:Object):void {
if (value != null) {
_data = value;
flag = 1;
//Alert.show("taskName.text: name:"+_data.task);
invalidateProperties();
dispatchEvent(new
FlexEvent(FlexEvent.DATA_CHANGE));
}
}
and in the commitProperties() method also as shown below
override protected function commitProperties():void {
super.commitProperties();
hBox.horizontalScrollPolicy = "off"; ............
if (flag != 0 ) {
task.text = _data.task;
category.text = _data.category;
priority.text = _data.priority;
}
}
It work's for me.
-sankar
On Mar 12, 6:57 pm, sankar swaroop <[email protected]> wrote:
> Hi shankar,
> Try this one. This may help you.
> There is a property called creationPolicy and set it to "all".
> This is a property for containers and this property initializes all its
> child components of a parent component.
>
> On 3/12/09, Sankar <[email protected]> wrote:
>
>
>
> > That is not the reason because even if i create the initData array
> > collection object with the new keyword am getting the same error.
>
> > See even if you create with new keyword, you don't have data
> > property available since you don't have the data getting bounded to
> > the array collection object and it is a null only but where as
> > itemRenderer is getting executing by that time.This is the reason am
> > getting the error.
>
> > I think the solution is that itemrenderer should be executed only
> > when the data gets bounded to initData.
>
> > Thanks
> > sankar
> > On Mar 12, 5:21 pm, Ravi Mishra <[email protected]> wrote:
> > > I got the problem when your application loads it finds the initData as
> > > null because you have assigned the null value to it and that is why
> > > you are getting the error message.
>
> > > Try doing it using the new keyword. Like this
>
> > > [Bindable]
> > > private var initData:ArrayCollection = new ArrayCollection();
>
> > > HTH,
>
> > > -Ravi
>
> > > On Mar 12, 2:10 pm, Sankar <[email protected]> wrote:
>
> > > > here am sending only the Application file and am using the same
> > > > itemrenderer which is in my previous posts.
>
> > > > Application File:
>
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> > > > layout="absolute" initialize="initList()" creationComplete="getData()>
>
> > > > <mx:Script>
> > > > <![CDATA[
> > > > import mx.collections.ArrayCollection;
>
> > > > [Bindable]
> > > > private var initData:ArrayCollection = null;
>
> > > > private function initList():void {
> > > > addEventListener("getItems",
> > > > getItemsEventHandler);
> > > > }
>
> > > > private function getData():void
> > > > {
> > > > try {
> > > > //am calling the backend
> > method here
> > > > (services code which
> > actually calls the backend
> > > > code using Remote Object)
> > > > }
> > > > catch(errObject:Error) {
> > > > trace(errObject.message);
> > > > }
> > > > }
>
> > > > private function getItemsEventHandler
> > > > (event:GetTodoItemsResultEvent):void {
>
> > > > initData = event.result;
> > > > }
> > > > ]]>
> > > > </mx:Script>
>
> > > > <mx:List dataProvider="{initData}" width="50%" height="50%"
> > > > itemRenderer="components.RendererInAS"/>
>
> > > > </mx:Application>
>
> > > > On Mar 12, 1:40 pm, Ravi Mishra <[email protected]> wrote:
>
> > > > > Can you pls send the code where you are declaring the
> > arraycollection?
>
> > > > > -Ravi
>
> > > > > On Mar 12, 12:24 pm, Sankar <[email protected]> wrote:
>
> > > > > > Hi,
> > > > > > It works fine, if the data(ArrayCollection) is static but it
> > > > > > doesn't work if the data is dynamic i.e if you try to get the data
> > > > > > from the database and am getting the runtime error as shown below
>
> > > > > > Cannot access a property or method of a null object
> > > > > > reference
>
> > > > > > at the line where we were setting the value to the labels in the
> > > > > > commitProprties() method.Since we all know that, child component
> > > > > > elements(controls) will be created and initialized first and then
> > > > > > parent components will be created and initialized.In my parent
> > > > > > component am firing the creationComplete event to get the data from
> > > > > > the Database and it will be fired after the child components has
> > been
> > > > > > created and initialized.
>
> > > > > > In this case, first item renderer written in action script
> > will
> > > > > > be executed and in that we were trying to set the values to labels
> > and
> > > > > > the data property not available by that time and then
> > creationComplete
> > > > > > event of it's parent component gets fired and now we will have the
> > > > > > data from the database.I think from 2nd time onwards data property
> > > > > > will be available.
>
> > > > > > How do i solve this problem? I think itemrenderer should be
> > executed
> > > > > > only when the data from the database gets bounded to
> > arrayCollection
> > > > > > object.
> > > > > > Is it correct?
>
> > > > > > Please, Can anyone help me ?
>
> > > > > > Thanks
> > > > > > sankar
>
> > > > > > On Mar 11, 7:45 pm, Sankar <[email protected]> wrote:
>
> > > > > > > Hi Ravi,
>
> > > > > > > I have seen your latest post and my problem got solved now.As
> > you
> > > > > > > said i added that statement and it works fine.
>
> > > > > > > Thanks
> > > > > > > sankar
>
> > > > > > > On Mar 11, 7:11 pm, Ravi Mishra <[email protected]> wrote:
>
> > > > > > > > Check out my second post in this thread which is as follows
>
> > > > > > > > I am sorry that I misunderstood your question.
>
> > > > > > > > You actually missed out a statement in createChildren Method.
> > Just add
> > > > > > > > 'this.addChild(hBox);' at the end of createChildren method.
>
> > > > > > > > HTH,
>
> > > > > > > > -Ravi
>
> > > > > > > > On Mar 11, 4:15 pm, Sankar <[email protected]> wrote:
>
> > > > > > > > > Hi Ravi Mishra,
>
> > > > > > > > > I already have seen this example but it doesn't help me .
> > In this
> > > > > > > > > example data getting displayed with the help of
> > DataGridColumn and in
> > > > > > > > > the itemRenderer written in actionScript just does the
> > decoration by
> > > > > > > > > overriding the setter for data property.
>
> > > > > > > > > But what am i trying to do is i wanted to laydown the
> > controls also
> > > > > > > > > in the action script itself like how we use the containers
> > say HBox in
> > > > > > > > > the custom itemRenderer in MXML and data proprty. I think in
> > this
> > > > > > > > > case the link what you send doesn't help me.
>
> > > > > > > > > Thanks
> > > > > > > > > sankar
>
> > > > > > > > > On Mar 11, 1:52 pm, Ravi Mishra <[email protected]>
> > wrote:
>
> > > > > > > > > > Hi Sankar,
>
> > > > > > > > > > You are on the wrong way. This is not the way you write an
> > > > > > > > > > itemRenderer. Please refer the folllowing link to get a
> > clear idea
> > > > > > > > > > about itemrenderers in actionscript.
>
> >http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/ww...
>
> > > > > > > > > > HTH,
>
> > > > > > > > > > -Ravi
>
> > > > > > > > > > On Mar 11, 9:31 am, Sankar <[email protected]>
> > wrote:
>
> > > > > > > > > > > Hi All,
>
> > > > > > > > > > > am trying to build item renderer for a List component in
> > action
> > > > > > > > > > > script rather than in mxml. In the action script class am
> > creating a
> > > > > > > > > > > HBox dynamically and adding Labels to is by overriding
> > the
> > > > > > > > > > > createChildern() and also overriding the
> > updateDisplayList() and
> > > > > > > > > > > commitProperties() and in which am setting the values to
> > labels.
>
> > > > > > > > > > > When i run the application in debug mode am
> > able to see the
> > > > > > > > > > > values being set to the labels but am not seeing the
> > values getting
> > > > > > > > > > > displayed in the List control.
>
> > > > > > > > > > > Here am posting the code,so that the problem can
> > be
> > > > > > > > > > > identified.
>
> > > > > > > > > > > Can anyone help me how to resolve this problem?
>
> > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?>
> > > > > > > > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
> > "
> > > > > > > > > > > layout="absolute">
> > > > > > > > > > > <mx:Script>
> > > > > > > > > > > <![CDATA[
> > > > > > > > > > > import
> > mx.collections.ArrayCollection;
>
> > > > > > > > > > > [Bindable]
> > > > > > > > > > > private var
> > initData:ArrayCollection = new ArrayCollection([
> > > > > > > > > > > {task:"pay bill",
> > category:"Office",priority:"Medium"},
> > > > > > > > > > > {task:"meet ravi on
> > sunday",category:"personal",priority:"Low"},
> > > > > > > > > > > {task:"buy a
> > book",category:"friends",priority:"Medium"},
> > > > > > > > > > > {task:"play
> > cricket",category:"friends",priority:"Low"},
> > > > > > > > > > > ]);
> > > > > > > > > > > ]]>
> > > > > > > > > > > </mx:Script>
>
> > > > > > > > > > > <mx:List dataProvider="{initData}" width="50%"
> > height="50%"
> > > > > > > > > > > itemRenderer="components.RendererInAS"/>
> > > > > > > > > > > </mx:Application>
>
> > > > > > > > > > > ItemRenderer file :
>
> > > > > > > > > > > package components
> > > > > > > > > > > {
>
> > > > > > > > > > > import mx.containers.HBox;
> > > > > > > > > > > import mx.controls.Label;
> > > > > > > > > > > import mx.controls.listClasses.BaseListData;
> > > > > > > > > > > import
> > mx.controls.listClasses.IDropInListItemRenderer;
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---