You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Tintin <19...@googlemail.com> on 2014/10/13 15:32:52 UTC

How Should I Dynamically Switch Component?

Hello

I am developing an application with an MVC structure. In my 'View' I have an
MXML component, let's call it Main_View, in which I want to display only 1
of 3 different child MXML components depending on values in my 'Model'.

At first I thought I would create 3 States and bind the currentState to a
property in my Main_Presenter ActionScript class in my 'Presenter' package
like this:



It appears though that you can't bind the currentState property. How can I
switch components as values in my MainPresenter change please?

Thank you.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-Should-I-Dynamically-Switch-Component-tp8378.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: How Should I Dynamically Switch Component?

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
Great, glad it's working.

-Mark

-----Original Message-----
From: Tintin [mailto:1955.mille.miglia@googlemail.com]
Sent: Tuesday, October 14, 2014 6:03 AM
To: users@flex.apache.org
Subject: RE: How Should I Dynamically Switch Component?

Hello Mark

Ok I have got it working with a very neat and simple solution.

In my MXML component I call a function in my 'Presenter' from the
onCreationComplete event:



In my ActionScript class I get a reference to the currentTarget, using the
event argument, and set a variable:



Now I can simply change the 'currentState' property of my _view property
like this:



Back in the View MXML component the 'includeIn' properties now cause the
different components to appear or not depending on the currentState of my
_view property.

It works a treat!



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-Should-I-Dynamically-Switch-Component-tp8378p8399.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: How Should I Dynamically Switch Component?

Posted by Tintin <19...@googlemail.com>.
Hello Mark

Ok I have got it working with a very neat and simple solution.

In my MXML component I call a function in my 'Presenter' from the
onCreationComplete event:



In my ActionScript class I get a reference to the currentTarget, using the
event argument, and set a variable:



Now I can simply change the 'currentState' property of my _view property
like this:



Back in the View MXML component the 'includeIn' properties now cause the
different components to appear or not depending on the currentState of my
_view property.

It works a treat!



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-Should-I-Dynamically-Switch-Component-tp8378p8399.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: How Should I Dynamically Switch Component?

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
Have you tried the includeIn and excludeFrom properties when using states?

-Mark

-----Original Message-----
From: Tintin [mailto:1955.mille.miglia@googlemail.com]
Sent: Monday, October 13, 2014 9:33 AM
To: users@flex.apache.org
Subject: How Should I Dynamically Switch Component?

Hello

I am developing an application with an MVC structure. In my 'View' I have an
MXML component, let's call it Main_View, in which I want to display only 1
of 3 different child MXML components depending on values in my 'Model'.

At first I thought I would create 3 States and bind the currentState to a
property in my Main_Presenter ActionScript class in my 'Presenter' package
like this:



It appears though that you can't bind the currentState property. How can I
switch components as values in my MainPresenter change please?

Thank you.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-Should-I-Dynamically-Switch-Component-tp8378.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: How Should I Dynamically Switch Component?

Posted by Tintin <19...@googlemail.com>.
Hello Piotr

Yes, in fact I kept going back and checking this because it is easy to
forget!



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-Should-I-Dynamically-Switch-Component-tp8378p8398.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: How Should I Dynamically Switch Component?

Posted by piotrz <pi...@gmail.com>.
Hi Tintin,

It is strange. I did something like that couple of times. Did you mark
currentState in your presenter as Bindable ?

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-Should-I-Dynamically-Switch-Component-tp8378p8379.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.