You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by pawan yadav <pa...@evolphin.com> on 2015/03/11 15:30:29 UTC

Maintaining Component without parent

Hi - Is it possible to maintain some UIComponent with adding it to any
parent component.

I need to keep mx in hidden state but want to update the data into it like
selected item. Since it is not added to any parent component that's why its
commit properties methods is not getting called.

I know If I do includeInLayout= false then it will work but without adding
this element can somehow call its commit properties method.

Re: Maintaining Component without parent

Posted by Alex Harui <ah...@adobe.com>.
I did a simple test that worked for me.  In the creationComplete handler
of a simple app, I did this:

private function testNestLevel():void
            {
  var s:TextArea = new TextArea();
  s.nestLevel = 2;
  s.validateNow();
            }

In the debugger, I saw validateNow go into the TextArea’s commitProperties.

-Alex



On 3/11/15, 8:36 AM, "Pawan Yadav" <pa...@gmail.com> wrote:

>No luck, It didn't work with nestLevel = 2.
>Not getting any call in commitproperties method through validateNow()
>
>
>
>Best Regards
>Pawan
>
>On Wed, Mar 11, 2015 at 8:40 PM, Alex Harui <ah...@adobe.com> wrote:
>
>>
>> On 3/11/15, 7:50 AM, "Jeffry Houser" <je...@dot-com-it.com> wrote:
>>
>> >
>> >  I did this back in "the day" when creating the watermark I used for
>> >Flextras components.  I basically created a component, rendered it, and
>> >turned it into a bitmap before ever putting it on the stage.
>> >
>> >  I had to write my own routine to force the component to go through
>> >it's life cycle  w/o being added to the stage.  I don't remember
>> >specifics.  I think it was more complicate than calling validatenow( ),
>> >but at the moment I can't imagine why.
>>
>> Because without a parent, it doesn't go in the queue such that
>>validateNow
>> will process it.
>>
>> I'm not sure it will work, but you could try setting nestLevel=2.  That
>> should allow it to go in the queues and get processed by validateNow()
>>or
>> regular layoutManager validation.  The question would be whether there
>>are
>> any dependencies on having a parent in the code that will run during
>> invalidation or validation. YMMV.
>>
>> -Alex
>>
>>
>>


Re: Maintaining Component without parent

Posted by Pawan Yadav <pa...@gmail.com>.
Thanks guys - It worked!

Best Regards
Pawan

On Thu, Mar 12, 2015 at 8:08 PM, Alex Harui <ah...@adobe.com> wrote:

> First some trivia:
>
> -Adding a component to the stage is what sets the nestLevel.
> -I saw yesterday that you can just set nestLevel and skip adding to stage,
> but other things may not work like style lookups.
> -Calling validateProperties also resets the invalidateProperties flag.
>
> Besides the calling of these invalidate/validation methods, another part
> of the component lifecycle is how it gets sized.  In Flex, children are
> sized by their parents.  If you don't explicitly set the proper size on a
> component it might layout in a surprising way or not show up at all
> because it is 0x0.
>
> -Alex
>
> On 3/11/15, 9:25 PM, "Pawan Yadav" <pa...@gmail.com> wrote:
>
> >Calling commitProperties directly will work but after that if this
> >component gets added then it is not showing display list properly. Instead
> >of creating news rows and align them properly it keeps on putting
> >everything on first row itself.
> >
> >Best Regards
> >Pawan
> >
> >On Thu, Mar 12, 2015 at 9:45 AM, Jake Knerr <ja...@ardisialabs.com> wrote:
> >
> >> Hi Jeffry,
> >>
> >> *Why wouldn't you just call commitProperties() directly?*
> >>
> >> commitProperties() is a protected method.
> >>
> >> The OP stated that he is working with *some UIComponent *and that he
> >> changed public properties such as *includeInLayout= false *and
> >> *selectedItem**. *I took this to mean he is asking how to manipulate the
> >> component's state using the component's public interface.
> >>
> >> If he is going to create a subclass of UIComponent and add state logic
> >> internally, he may as well call commitProperties() directly within the
> >> component.
> >>
> >> On Wed, Mar 11, 2015 at 9:16 PM, Jeffry Houser <je...@dot-com-it.com>
> >> wrote:
> >>
> >> >  On 3/11/2015 10:38 PM, Jake Knerr wrote:
> >> >
> >> >  To the OP: if you don't want to extend the component, you should be
> >>able
> >> > to get commitProperties() to fire on a component that has not been
> >>added
> >> to
> >> > the displayList by first calling invalidateProperties() and then call
> >> > validateProperties().
> >> >
> >> >  *E.G.*
> >> > var cmp:UIComponent = new UIComponent();
> >> > cmp.invalidateProperties();
> >> > cmp.validateProperties();
> >> >
> >> >  For the above example, cmp's commitProperties() method will fire even
> >> > though the component isn't on the displayList.
> >> > Both invalidateProperties() and validateProperties() are required.
> >> >
> >> >
> >> >   Why wouldn't you just call commitProperties() directly?
> >> >
> >> > --
> >> > Jeffry Houser
> >> > Technical Entrepreneurhttp://www.jeffryhouser.com203-379-0773
> >> >
> >> >
> >>
> >>
> >> --
> >> Jake Knerr - Flex Developer
> >> Ardisia Labs
> >> www.ardisialabs.com
> >>
>
>

Re: Maintaining Component without parent

Posted by Alex Harui <ah...@adobe.com>.
First some trivia:

-Adding a component to the stage is what sets the nestLevel.
-I saw yesterday that you can just set nestLevel and skip adding to stage,
but other things may not work like style lookups.
-Calling validateProperties also resets the invalidateProperties flag.

Besides the calling of these invalidate/validation methods, another part
of the component lifecycle is how it gets sized.  In Flex, children are
sized by their parents.  If you don’t explicitly set the proper size on a
component it might layout in a surprising way or not show up at all
because it is 0x0.

-Alex

On 3/11/15, 9:25 PM, "Pawan Yadav" <pa...@gmail.com> wrote:

>Calling commitProperties directly will work but after that if this
>component gets added then it is not showing display list properly. Instead
>of creating news rows and align them properly it keeps on putting
>everything on first row itself.
>
>Best Regards
>Pawan
>
>On Thu, Mar 12, 2015 at 9:45 AM, Jake Knerr <ja...@ardisialabs.com> wrote:
>
>> Hi Jeffry,
>>
>> *Why wouldn't you just call commitProperties() directly?*
>>
>> commitProperties() is a protected method.
>>
>> The OP stated that he is working with *some UIComponent *and that he
>> changed public properties such as *includeInLayout= false *and
>> *selectedItem**. *I took this to mean he is asking how to manipulate the
>> component's state using the component's public interface.
>>
>> If he is going to create a subclass of UIComponent and add state logic
>> internally, he may as well call commitProperties() directly within the
>> component.
>>
>> On Wed, Mar 11, 2015 at 9:16 PM, Jeffry Houser <je...@dot-com-it.com>
>> wrote:
>>
>> >  On 3/11/2015 10:38 PM, Jake Knerr wrote:
>> >
>> >  To the OP: if you don't want to extend the component, you should be
>>able
>> > to get commitProperties() to fire on a component that has not been
>>added
>> to
>> > the displayList by first calling invalidateProperties() and then call
>> > validateProperties().
>> >
>> >  *E.G.*
>> > var cmp:UIComponent = new UIComponent();
>> > cmp.invalidateProperties();
>> > cmp.validateProperties();
>> >
>> >  For the above example, cmp's commitProperties() method will fire even
>> > though the component isn't on the displayList.
>> > Both invalidateProperties() and validateProperties() are required.
>> >
>> >
>> >   Why wouldn't you just call commitProperties() directly?
>> >
>> > --
>> > Jeffry Houser
>> > Technical Entrepreneurhttp://www.jeffryhouser.com203-379-0773
>> >
>> >
>>
>>
>> --
>> Jake Knerr - Flex Developer
>> Ardisia Labs
>> www.ardisialabs.com
>>


Re: Maintaining Component without parent

Posted by Pawan Yadav <pa...@gmail.com>.
Calling commitProperties directly will work but after that if this
component gets added then it is not showing display list properly. Instead
of creating news rows and align them properly it keeps on putting
everything on first row itself.

Best Regards
Pawan

On Thu, Mar 12, 2015 at 9:45 AM, Jake Knerr <ja...@ardisialabs.com> wrote:

> Hi Jeffry,
>
> *Why wouldn't you just call commitProperties() directly?*
>
> commitProperties() is a protected method.
>
> The OP stated that he is working with *some UIComponent *and that he
> changed public properties such as *includeInLayout= false *and
> *selectedItem**. *I took this to mean he is asking how to manipulate the
> component's state using the component's public interface.
>
> If he is going to create a subclass of UIComponent and add state logic
> internally, he may as well call commitProperties() directly within the
> component.
>
> On Wed, Mar 11, 2015 at 9:16 PM, Jeffry Houser <je...@dot-com-it.com>
> wrote:
>
> >  On 3/11/2015 10:38 PM, Jake Knerr wrote:
> >
> >  To the OP: if you don't want to extend the component, you should be able
> > to get commitProperties() to fire on a component that has not been added
> to
> > the displayList by first calling invalidateProperties() and then call
> > validateProperties().
> >
> >  *E.G.*
> > var cmp:UIComponent = new UIComponent();
> > cmp.invalidateProperties();
> > cmp.validateProperties();
> >
> >  For the above example, cmp's commitProperties() method will fire even
> > though the component isn't on the displayList.
> > Both invalidateProperties() and validateProperties() are required.
> >
> >
> >   Why wouldn't you just call commitProperties() directly?
> >
> > --
> > Jeffry Houser
> > Technical Entrepreneurhttp://www.jeffryhouser.com203-379-0773
> >
> >
>
>
> --
> Jake Knerr - Flex Developer
> Ardisia Labs
> www.ardisialabs.com
>

Re: Maintaining Component without parent

Posted by Jake Knerr <ja...@ardisialabs.com>.
Hi Jeffry,

*Why wouldn't you just call commitProperties() directly?*

commitProperties() is a protected method.

The OP stated that he is working with *some UIComponent *and that he
changed public properties such as *includeInLayout= false *and
*selectedItem**. *I took this to mean he is asking how to manipulate the
component's state using the component's public interface.

If he is going to create a subclass of UIComponent and add state logic
internally, he may as well call commitProperties() directly within the
component.

On Wed, Mar 11, 2015 at 9:16 PM, Jeffry Houser <je...@dot-com-it.com>
wrote:

>  On 3/11/2015 10:38 PM, Jake Knerr wrote:
>
>  To the OP: if you don't want to extend the component, you should be able
> to get commitProperties() to fire on a component that has not been added to
> the displayList by first calling invalidateProperties() and then call
> validateProperties().
>
>  *E.G.*
> var cmp:UIComponent = new UIComponent();
> cmp.invalidateProperties();
> cmp.validateProperties();
>
>  For the above example, cmp's commitProperties() method will fire even
> though the component isn't on the displayList.
> Both invalidateProperties() and validateProperties() are required.
>
>
>   Why wouldn't you just call commitProperties() directly?
>
> --
> Jeffry Houser
> Technical Entrepreneurhttp://www.jeffryhouser.com203-379-0773
>
>


-- 
Jake Knerr - Flex Developer
Ardisia Labs
www.ardisialabs.com

Re: Maintaining Component without parent

Posted by Jeffry Houser <je...@dot-com-it.com>.
On 3/11/2015 10:38 PM, Jake Knerr wrote:
> //
> To the OP: if you don't want to extend the component, you should be 
> able to get commitProperties() to fire on a component that has not 
> been added to the displayList by first calling invalidateProperties() 
> and then call validateProperties().
>
> *E.G.*
> var cmp:UIComponent = new UIComponent();
> cmp.invalidateProperties();
> cmp.validateProperties();
>
> For the above example, cmp's commitProperties() method will fire even 
> though the component isn't on the displayList. 
> Both invalidateProperties() and validateProperties() are required.

   Why wouldn't you just call commitProperties() directly?

-- 
Jeffry Houser
Technical Entrepreneur
http://www.jeffryhouser.com
203-379-0773


Re: Maintaining Component without parent

Posted by Jake Knerr <ja...@ardisialabs.com>.
*If it isn't on the stage; then invalidateProperties will have no affect;
because the SystemManager (is that the right class?) is not aware of it;
and will push the component through its validation process.*

I didn't realize that the component hadn't been added to the displayList.
Serves me right for not fully reading the question and firing off a
half-baked suggestion. Let me try again....

To the OP: if you don't want to extend the component, you should be able to
get commitProperties() to fire on a component that has not been added to
the displayList by first calling invalidateProperties() and then call
validateProperties().

*E.G.*
var cmp:UIComponent = new UIComponent();
cmp.invalidateProperties();
cmp.validateProperties();

For the above example, cmp's commitProperties() method will fire even
though the component isn't on the displayList.
Both invalidateProperties() and validateProperties() are required.


On Wed, Mar 11, 2015 at 4:32 PM, Jeffry Houser <je...@dot-com-it.com>
wrote:

> On 3/11/2015 1:01 PM, Jake Knerr wrote:
>
>> Try calling invalidateProperties() before calling validateNow() to get
>> commitProperties() to fire.
>>
>  If it isn't on the stage; then invalidateProperties will have no affect;
> because the SystemManager (is that the right class?) is not aware of it;
> and will push the component through its validation process.
> I pulled up the old code.  This was my render method for both MX and Spark
> components.
>
>
>         public function render(argInheritingStyles : Object):void{
>             this.createChildren();
>             this.childrenCreated();
>             this.initializationComplete();
>             this.inheritingStyles = argInheritingStyles;
>             this.commitProperties();
>             this.setStyle('paddingLeft',0);
>             this.setStyle('paddingRight',0);
>             this.setStyle('paddingTop',0);
>             this.setStyle('paddingBottom',0);
>             this.measure();
>             this.height = this.measuredHeight;
>             this.width = this.measuredWidth;
> this.updateDisplayList(this.unscaledWidth,this.unscaledHeight);
>         }
>
>
> Since it sounds like you want to 'use' and interact with the component;
> you'll probably also need a method that does update cycles.
>
>
> --
> Jeffry Houser
> Technical Entrepreneur
> http://www.jeffryhouser.com
> 203-379-0773
>
>


-- 
Jake Knerr - Flex Developer
Ardisia Labs
www.ardisialabs.com

Re: Maintaining Component without parent

Posted by Jeffry Houser <je...@dot-com-it.com>.
On 3/11/2015 1:01 PM, Jake Knerr wrote:
> Try calling invalidateProperties() before calling validateNow() to get
> commitProperties() to fire.
  If it isn't on the stage; then invalidateProperties will have no 
affect; because the SystemManager (is that the right class?) is not 
aware of it; and will push the component through its validation process.
I pulled up the old code.  This was my render method for both MX and 
Spark components.


         public function render(argInheritingStyles : Object):void{
             this.createChildren();
             this.childrenCreated();
             this.initializationComplete();
             this.inheritingStyles = argInheritingStyles;
             this.commitProperties();
             this.setStyle('paddingLeft',0);
             this.setStyle('paddingRight',0);
             this.setStyle('paddingTop',0);
             this.setStyle('paddingBottom',0);
             this.measure();
             this.height = this.measuredHeight;
             this.width = this.measuredWidth;
this.updateDisplayList(this.unscaledWidth,this.unscaledHeight);
         }


Since it sounds like you want to 'use' and interact with the component; 
you'll probably also need a method that does update cycles.

-- 
Jeffry Houser
Technical Entrepreneur
http://www.jeffryhouser.com
203-379-0773


Re: Maintaining Component without parent

Posted by Jake Knerr <ja...@ardisialabs.com>.
Try calling invalidateProperties() before calling validateNow() to get
commitProperties() to fire.

On Wed, Mar 11, 2015 at 9:36 AM, Pawan Yadav <pa...@gmail.com> wrote:

> No luck, It didn't work with nestLevel = 2.
> Not getting any call in commitproperties method through validateNow()
>
>
>
> Best Regards
> Pawan
>
> On Wed, Mar 11, 2015 at 8:40 PM, Alex Harui <ah...@adobe.com> wrote:
>
> >
> > On 3/11/15, 7:50 AM, "Jeffry Houser" <je...@dot-com-it.com> wrote:
> >
> > >
> > >  I did this back in "the day" when creating the watermark I used for
> > >Flextras components.  I basically created a component, rendered it, and
> > >turned it into a bitmap before ever putting it on the stage.
> > >
> > >  I had to write my own routine to force the component to go through
> > >it's life cycle  w/o being added to the stage.  I don't remember
> > >specifics.  I think it was more complicate than calling validatenow( ),
> > >but at the moment I can't imagine why.
> >
> > Because without a parent, it doesn't go in the queue such that
> validateNow
> > will process it.
> >
> > I'm not sure it will work, but you could try setting nestLevel=2.  That
> > should allow it to go in the queues and get processed by validateNow() or
> > regular layoutManager validation.  The question would be whether there
> are
> > any dependencies on having a parent in the code that will run during
> > invalidation or validation. YMMV.
> >
> > -Alex
> >
> >
> >
>



-- 
Jake Knerr - Flex Developer
Ardisia Labs
www.ardisialabs.com

Re: Maintaining Component without parent

Posted by Pawan Yadav <pa...@gmail.com>.
No luck, It didn't work with nestLevel = 2.
Not getting any call in commitproperties method through validateNow()



Best Regards
Pawan

On Wed, Mar 11, 2015 at 8:40 PM, Alex Harui <ah...@adobe.com> wrote:

>
> On 3/11/15, 7:50 AM, "Jeffry Houser" <je...@dot-com-it.com> wrote:
>
> >
> >  I did this back in "the day" when creating the watermark I used for
> >Flextras components.  I basically created a component, rendered it, and
> >turned it into a bitmap before ever putting it on the stage.
> >
> >  I had to write my own routine to force the component to go through
> >it's life cycle  w/o being added to the stage.  I don't remember
> >specifics.  I think it was more complicate than calling validatenow( ),
> >but at the moment I can't imagine why.
>
> Because without a parent, it doesn't go in the queue such that validateNow
> will process it.
>
> I'm not sure it will work, but you could try setting nestLevel=2.  That
> should allow it to go in the queues and get processed by validateNow() or
> regular layoutManager validation.  The question would be whether there are
> any dependencies on having a parent in the code that will run during
> invalidation or validation. YMMV.
>
> -Alex
>
>
>

Re: Maintaining Component without parent

Posted by Alex Harui <ah...@adobe.com>.
On 3/11/15, 7:50 AM, "Jeffry Houser" <je...@dot-com-it.com> wrote:

>
>  I did this back in "the day" when creating the watermark I used for
>Flextras components.  I basically created a component, rendered it, and
>turned it into a bitmap before ever putting it on the stage.
>
>  I had to write my own routine to force the component to go through
>it's life cycle  w/o being added to the stage.  I don't remember
>specifics.  I think it was more complicate than calling validatenow( ),
>but at the moment I can't imagine why.

Because without a parent, it doesn’t go in the queue such that validateNow
will process it.

I’m not sure it will work, but you could try setting nestLevel=2.  That
should allow it to go in the queues and get processed by validateNow() or
regular layoutManager validation.  The question would be whether there are
any dependencies on having a parent in the code that will run during
invalidation or validation. YMMV.

-Alex



Re: Maintaining Component without parent

Posted by Jeffry Houser <je...@dot-com-it.com>.
  I did this back in "the day" when creating the watermark I used for 
Flextras components.  I basically created a component, rendered it, and 
turned it into a bitmap before ever putting it on the stage.

  I had to write my own routine to force the component to go through 
it's life cycle  w/o being added to the stage.  I don't remember 
specifics.  I think it was more complicate than calling validatenow( ), 
but at the moment I can't imagine why.

On 3/11/2015 10:43 AM, Carlos Velasco wrote:
> Extend the component to use a custom data object as its data source. So
> update the commit properties and lifecycle functions to get the current
> data from the object.
>
> Then what you have to ensure is that your data object is live, rather than
> worrying about the component.
>
> 2015-03-11 11:30 GMT-03:00 pawan yadav <pa...@evolphin.com>:
>
>> Hi - Is it possible to maintain some UIComponent with adding it to any
>> parent component.
>>
>> I need to keep mx in hidden state but want to update the data into it like
>> selected item. Since it is not added to any parent component that's why its
>> commit properties methods is not getting called.
>>
>> I know If I do includeInLayout= false then it will work but without adding
>> this element can somehow call its commit properties method.
>>


-- 
Jeffry Houser
Technical Entrepreneur
http://www.jeffryhouser.com
203-379-0773


Re: Maintaining Component without parent

Posted by Carlos Velasco <ca...@gmail.com>.
Extend the component to use a custom data object as its data source. So
update the commit properties and lifecycle functions to get the current
data from the object.

Then what you have to ensure is that your data object is live, rather than
worrying about the component.

2015-03-11 11:30 GMT-03:00 pawan yadav <pa...@evolphin.com>:

> Hi - Is it possible to maintain some UIComponent with adding it to any
> parent component.
>
> I need to keep mx in hidden state but want to update the data into it like
> selected item. Since it is not added to any parent component that's why its
> commit properties methods is not getting called.
>
> I know If I do includeInLayout= false then it will work but without adding
> this element can somehow call its commit properties method.
>