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/01/25 21:22:26 UTC

Can I Bind a SolidColor Fill Value?

Hello

I have defined a Spark Rect and want to bind its fill value to a property in
a presenter file, is this possible?

I have declared my presenter Class as [Bindable]. In my presenter I have a
property as follows:


I have a Switch statement to change the value depending on the value of
another property which may change:


In my mxml file I have defined a Rectangle as follows:


Frustratingly my rectangle remains black even though I know the Switch
statement is working, as initially set in the class. I'm sure there's a
'schoolboy error' somewhere but I can't see it!

Regards

Chris



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Can I Bind a SolidColor Fill Value?

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

As soon as I read your reply I realised that I should have noticed that. Thank you very much for your support with this. I will make the adjustment later today and let you know how it goes. Great learning along the way.

Regards
Chris

On 7 Feb 2014, at 10:32, "Martin Miko [via Apache Flex Users]" <ml...@n4.nabble.com> wrote:

> Hi Chris, 
> 
> yeah, sorry my mistake, I wrote it hastily and forgot kinda important line 
> there: 
> 
> *super.partAdded(partName, instance);* 
> 
> so the correct function should look like this: 
> 
> override protected function partAdded(partName:String, 
> instance:Object):void { 
>     super. partAdded(partName, instance); 
>     if (partName == "thumb") { 
>         thumbInst = instance; 
>     } 
> } 
> 
> Explanation: 
> You are overriding inherited function, so you need to call the inherited 
> one as well. 
> That's the one used in the parent class, because it adds all click events 
> and lots 
> more. If you just override it and don't call super.partAdded() all this 
> "magic behind the scenes" is not done and the slider is not clickable or 
> movable. 
> 
> Hope it'll work now, if you have any other question, feel free to ask. 
> 
> BR, 
> Martin 
> 
> 
> On Fri, Feb 7, 2014 at 10:20 AM, Tintin <[hidden email]>wrote: 
> 
> > Hello Martin 
> > 
> > I'm inching closer! I looked carefully at my code again last night, 
> > particularly at the passing of the presenter class to the Thumb Skin. I saw 
> > that your example code in the customSlider_creationCompleteHandler you 
> > assigned a new instance of SliderView_Presenter to variable 'p' and then 
> > passed this to the 'presenter' property of the customSlider. What I needed 
> > was to assign 'this' to 'p' in my SliderView_Presenter and pass it to the 
> > customSlider. That done, as my buttonColour property changes in 
> > SliderView_Presenter the Skin Rect fill colour, bound to the buttonColour 
> > property, now changes. Yippee! 
> > 
> > However (and it was going so well!) the following function prevents the 
> > HSlider button from moving: 
> > 
> >     override protected function partAdded(partName:String, 
> > instance:Object):void { 
> >         if (partName == "thumb") { 
> >             _thumbInst = instance; 
> >         } 
> > 
> > Can you suggest why the Thumb button is no longer draggable? 
> > 
> > Thank you. 
> > 
> > Chris 
> > 
> > 
> > On 6 Feb 2014, at 17:12, Martin Miko [via Apache Flex Users] wrote: 
> > 
> > > Hi Chris, 
> > > 
> > > yes, basically the presenter variable defined in the thumb skin is done 
> > > like this: 
> > > 
> > >     <fx:Declarations> 
> > >         <presenters:SliderView_Presenter id="presenter" /> 
> > >     </fx:Declarations> 
> > > 
> > > you add these 3 lines, and then use the presenter.buttonColour in the 
> > > component where you want to use it. 
> > > 
> > > BR, 
> > > Martin Miko 
> > > 
> > > 
> > > On Thu, Feb 6, 2014 at 10:28 AM, Tintin <[hidden email]>wrote: 
> > > 
> > > > Hi Martin 
> > > > 
> > > > Would you please explain one last point which I can't quite see. You 
> > use 
> > > > the following code in the custom HSlider: 
> > > > 
> > > > // injecting the presenter 
> > > >         public function set presenter(p:SliderView_Presenter):void { 
> > > >             _presenter = p; 
> > > > 
> > > >             if (thumbInst) 
> > > >                 thumbInst.skin.presenter = _presenter; 
> > > >         } 
> > > > 
> > > > Did you create a property named 'presenter' within the Thumb's skin 
> > mxml 
> > > > file to pass it the HSlider's presenter class? 
> > > > 
> > > > I can see that I need to pass the presenter to the Thumb's skin so 
> > that I 
> > > > can bind my Thumb Rect Fill Color property back to the uint property 
> > > > defined in my SliderView_Presenter class, but I can't see quite how. 
> > > > 
> > > > Thanks 
> > > > 
> > > > Chris 
> > > > 
> > > > On 4 Feb 2014, at 18:49, Martin Miko [via Apache Flex Users] wrote: 
> > > > 
> > > > > Hi Chris, 
> > > > > 
> > > > > I guess you almost have it working now! :) As you wrote in your 
> > previous 
> > > > > message, you need to pass the SliderView_Presenter instance all the 
> > way 
> > > > > from the place where you created it, to the place where you want to 
> > use 
> > > > it 
> > > > > (skin). If you pass that instance all the way to the thumb button's 
> > skin, 
> > > > > then you can use the data binding exactly in the way you wanted. 
> > > > > 
> > > > > 
> > > > > BR, 
> > > > > Martin Miko 
> > > > > 
> > > > > 
> > > > > On Tue, Feb 4, 2014 at 5:49 PM, Tintin <[hidden email]>wrote: 
> > > > > 
> > > > > > Thank you for your considered replies. I'm starting to get it now. 
> > > > > > 
> > > > > > It looks as if you are creating a custom HSlider with additional 
> > > > properties 
> > > > > > named 'presenter' and 'thumbInst'. When the creationComplete event 
> > is 
> > > > > > called 
> > > > > > you pass in the SliderView_Presenter class. When you Set the 
> > presenter 
> > > > > > property you check to ensure you have an instance of the 'thumb' 
> > part 
> > > > and 
> > > > > > if 
> > > > > > you do then you assign thumbInst.skin.presenter the instance of 
> > > > > > SliderView_Presenter (this must have to be the same instance and 
> > not 
> > > > > > instantiate a new instance otherwise when a property in the 
> > original 
> > > > > > SliderView_Presenter class changes the skin will not see this 
> > change?). 
> > > > > > 
> > > > > > This looks to me as if I first need to create a property within the 
> > > > thumb 
> > > > > > skin named 'presenter' so that I can set it with the 
> > > > SliderView_Property 
> > > > > > instance I'm passing in? 
> > > > > > 
> > > > > > In my SliderView_Presenter class I assign a property named 
> > > > buttonColour a 
> > > > > > uint value by default and when a parameter is passed in from the 
> > host 
> > > > web 
> > > > > > page a simple switch function assigns the correct colour depending 
> > on 
> > > > the 
> > > > > > parameter value passed in. How can I use this to update, say a 
> > > > rectangle, 
> > > > > > in 
> > > > > > my skin please? 
> > > > > > 
> > > > > > Chris 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > -- 
> > > > > > View this message in context: 
> > > > > > 
> > > > 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4811.html
> > > > > > Sent from the Apache Flex Users mailing list archive at Nabble.com. 
> > > > > > 
> > > > > 
> > > > > 
> > > > > If you reply to this email, your message will be added to the 
> > discussion 
> > > > below: 
> > > > > 
> > > > 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4819.html
> > > > > To unsubscribe from Can I Bind a SolidColor Fill Value?, click here. 
> > > > > NAML 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > -- 
> > > > View this message in context: 
> > > > 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4848.html
> > > > Sent from the Apache Flex Users mailing list archive at Nabble.com. 
> > > > 
> > > 
> > > 
> > > If you reply to this email, your message will be added to the discussion 
> > below: 
> > > 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4854.html
> > > To unsubscribe from Can I Bind a SolidColor Fill Value?, click here. 
> > > NAML 
> > 
> > 
> > 
> > 
> > 
> > -- 
> > View this message in context: 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4880.html
> > Sent from the Apache Flex Users mailing list archive at Nabble.com. 
> > 
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4881.html
> To unsubscribe from Can I Bind a SolidColor Fill Value?, click here.
> NAML





--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4882.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Can I Bind a SolidColor Fill Value?

Posted by Martin Miko <ma...@gmail.com>.
Hi Chris,

yeah, sorry my mistake, I wrote it hastily and forgot kinda important line
there:

*super.partAdded(partName, instance);*

so the correct function should look like this:

override protected function partAdded(partName:String,
instance:Object):void {
    super. partAdded(partName, instance);
    if (partName == "thumb") {
        thumbInst = instance;
    }
}

Explanation:
You are overriding inherited function, so you need to call the inherited
one as well.
That's the one used in the parent class, because it adds all click events
and lots
more. If you just override it and don't call super.partAdded() all this
"magic behind the scenes" is not done and the slider is not clickable or
movable.

Hope it'll work now, if you have any other question, feel free to ask.

BR,
Martin


On Fri, Feb 7, 2014 at 10:20 AM, Tintin <19...@googlemail.com>wrote:

> Hello Martin
>
> I'm inching closer! I looked carefully at my code again last night,
> particularly at the passing of the presenter class to the Thumb Skin. I saw
> that your example code in the customSlider_creationCompleteHandler you
> assigned a new instance of SliderView_Presenter to variable 'p' and then
> passed this to the 'presenter' property of the customSlider. What I needed
> was to assign 'this' to 'p' in my SliderView_Presenter and pass it to the
> customSlider. That done, as my buttonColour property changes in
> SliderView_Presenter the Skin Rect fill colour, bound to the buttonColour
> property, now changes. Yippee!
>
> However (and it was going so well!) the following function prevents the
> HSlider button from moving:
>
>     override protected function partAdded(partName:String,
> instance:Object):void {
>         if (partName == "thumb") {
>             _thumbInst = instance;
>         }
>
> Can you suggest why the Thumb button is no longer draggable?
>
> Thank you.
>
> Chris
>
>
> On 6 Feb 2014, at 17:12, Martin Miko [via Apache Flex Users] wrote:
>
> > Hi Chris,
> >
> > yes, basically the presenter variable defined in the thumb skin is done
> > like this:
> >
> >     <fx:Declarations>
> >         <presenters:SliderView_Presenter id="presenter" />
> >     </fx:Declarations>
> >
> > you add these 3 lines, and then use the presenter.buttonColour in the
> > component where you want to use it.
> >
> > BR,
> > Martin Miko
> >
> >
> > On Thu, Feb 6, 2014 at 10:28 AM, Tintin <[hidden email]>wrote:
> >
> > > Hi Martin
> > >
> > > Would you please explain one last point which I can't quite see. You
> use
> > > the following code in the custom HSlider:
> > >
> > > // injecting the presenter
> > >         public function set presenter(p:SliderView_Presenter):void {
> > >             _presenter = p;
> > >
> > >             if (thumbInst)
> > >                 thumbInst.skin.presenter = _presenter;
> > >         }
> > >
> > > Did you create a property named 'presenter' within the Thumb's skin
> mxml
> > > file to pass it the HSlider's presenter class?
> > >
> > > I can see that I need to pass the presenter to the Thumb's skin so
> that I
> > > can bind my Thumb Rect Fill Color property back to the uint property
> > > defined in my SliderView_Presenter class, but I can't see quite how.
> > >
> > > Thanks
> > >
> > > Chris
> > >
> > > On 4 Feb 2014, at 18:49, Martin Miko [via Apache Flex Users] wrote:
> > >
> > > > Hi Chris,
> > > >
> > > > I guess you almost have it working now! :) As you wrote in your
> previous
> > > > message, you need to pass the SliderView_Presenter instance all the
> way
> > > > from the place where you created it, to the place where you want to
> use
> > > it
> > > > (skin). If you pass that instance all the way to the thumb button's
> skin,
> > > > then you can use the data binding exactly in the way you wanted.
> > > >
> > > >
> > > > BR,
> > > > Martin Miko
> > > >
> > > >
> > > > On Tue, Feb 4, 2014 at 5:49 PM, Tintin <[hidden email]>wrote:
> > > >
> > > > > Thank you for your considered replies. I'm starting to get it now.
> > > > >
> > > > > It looks as if you are creating a custom HSlider with additional
> > > properties
> > > > > named 'presenter' and 'thumbInst'. When the creationComplete event
> is
> > > > > called
> > > > > you pass in the SliderView_Presenter class. When you Set the
> presenter
> > > > > property you check to ensure you have an instance of the 'thumb'
> part
> > > and
> > > > > if
> > > > > you do then you assign thumbInst.skin.presenter the instance of
> > > > > SliderView_Presenter (this must have to be the same instance and
> not
> > > > > instantiate a new instance otherwise when a property in the
> original
> > > > > SliderView_Presenter class changes the skin will not see this
> change?).
> > > > >
> > > > > This looks to me as if I first need to create a property within the
> > > thumb
> > > > > skin named 'presenter' so that I can set it with the
> > > SliderView_Property
> > > > > instance I'm passing in?
> > > > >
> > > > > In my SliderView_Presenter class I assign a property named
> > > buttonColour a
> > > > > uint value by default and when a parameter is passed in from the
> host
> > > web
> > > > > page a simple switch function assigns the correct colour depending
> on
> > > the
> > > > > parameter value passed in. How can I use this to update, say a
> > > rectangle,
> > > > > in
> > > > > my skin please?
> > > > >
> > > > > Chris
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > View this message in context:
> > > > >
> > >
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4811.html
> > > > > Sent from the Apache Flex Users mailing list archive at Nabble.com.
> > > > >
> > > >
> > > >
> > > > If you reply to this email, your message will be added to the
> discussion
> > > below:
> > > >
> > >
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4819.html
> > > > To unsubscribe from Can I Bind a SolidColor Fill Value?, click here.
> > > > NAML
> > >
> > >
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4848.html
> > > Sent from the Apache Flex Users mailing list archive at Nabble.com.
> > >
> >
> >
> > If you reply to this email, your message will be added to the discussion
> below:
> >
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4854.html
> > To unsubscribe from Can I Bind a SolidColor Fill Value?, click here.
> > NAML
>
>
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4880.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Can I Bind a SolidColor Fill Value?

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

I'm inching closer! I looked carefully at my code again last night, particularly at the passing of the presenter class to the Thumb Skin. I saw that your example code in the customSlider_creationCompleteHandler you assigned a new instance of SliderView_Presenter to variable 'p' and then passed this to the 'presenter' property of the customSlider. What I needed was to assign 'this' to 'p' in my SliderView_Presenter and pass it to the customSlider. That done, as my buttonColour property changes in SliderView_Presenter the Skin Rect fill colour, bound to the buttonColour property, now changes. Yippee!

However (and it was going so well!) the following function prevents the HSlider button from moving:

    override protected function partAdded(partName:String, instance:Object):void {
        if (partName == "thumb") {
            _thumbInst = instance;
        }

Can you suggest why the Thumb button is no longer draggable?

Thank you.

Chris


On 6 Feb 2014, at 17:12, Martin Miko [via Apache Flex Users] wrote:

> Hi Chris, 
> 
> yes, basically the presenter variable defined in the thumb skin is done 
> like this: 
> 
>     <fx:Declarations> 
>         <presenters:SliderView_Presenter id="presenter" /> 
>     </fx:Declarations> 
> 
> you add these 3 lines, and then use the presenter.buttonColour in the 
> component where you want to use it. 
> 
> BR, 
> Martin Miko 
> 
> 
> On Thu, Feb 6, 2014 at 10:28 AM, Tintin <[hidden email]>wrote: 
> 
> > Hi Martin 
> > 
> > Would you please explain one last point which I can't quite see. You use 
> > the following code in the custom HSlider: 
> > 
> > // injecting the presenter 
> >         public function set presenter(p:SliderView_Presenter):void { 
> >             _presenter = p; 
> > 
> >             if (thumbInst) 
> >                 thumbInst.skin.presenter = _presenter; 
> >         } 
> > 
> > Did you create a property named 'presenter' within the Thumb's skin mxml 
> > file to pass it the HSlider's presenter class? 
> > 
> > I can see that I need to pass the presenter to the Thumb's skin so that I 
> > can bind my Thumb Rect Fill Color property back to the uint property 
> > defined in my SliderView_Presenter class, but I can't see quite how. 
> > 
> > Thanks 
> > 
> > Chris 
> > 
> > On 4 Feb 2014, at 18:49, Martin Miko [via Apache Flex Users] wrote: 
> > 
> > > Hi Chris, 
> > > 
> > > I guess you almost have it working now! :) As you wrote in your previous 
> > > message, you need to pass the SliderView_Presenter instance all the way 
> > > from the place where you created it, to the place where you want to use 
> > it 
> > > (skin). If you pass that instance all the way to the thumb button's skin, 
> > > then you can use the data binding exactly in the way you wanted. 
> > > 
> > > 
> > > BR, 
> > > Martin Miko 
> > > 
> > > 
> > > On Tue, Feb 4, 2014 at 5:49 PM, Tintin <[hidden email]>wrote: 
> > > 
> > > > Thank you for your considered replies. I'm starting to get it now. 
> > > > 
> > > > It looks as if you are creating a custom HSlider with additional 
> > properties 
> > > > named 'presenter' and 'thumbInst'. When the creationComplete event is 
> > > > called 
> > > > you pass in the SliderView_Presenter class. When you Set the presenter 
> > > > property you check to ensure you have an instance of the 'thumb' part 
> > and 
> > > > if 
> > > > you do then you assign thumbInst.skin.presenter the instance of 
> > > > SliderView_Presenter (this must have to be the same instance and not 
> > > > instantiate a new instance otherwise when a property in the original 
> > > > SliderView_Presenter class changes the skin will not see this change?). 
> > > > 
> > > > This looks to me as if I first need to create a property within the 
> > thumb 
> > > > skin named 'presenter' so that I can set it with the 
> > SliderView_Property 
> > > > instance I'm passing in? 
> > > > 
> > > > In my SliderView_Presenter class I assign a property named 
> > buttonColour a 
> > > > uint value by default and when a parameter is passed in from the host 
> > web 
> > > > page a simple switch function assigns the correct colour depending on 
> > the 
> > > > parameter value passed in. How can I use this to update, say a 
> > rectangle, 
> > > > in 
> > > > my skin please? 
> > > > 
> > > > Chris 
> > > > 
> > > > 
> > > > 
> > > > -- 
> > > > View this message in context: 
> > > > 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4811.html
> > > > Sent from the Apache Flex Users mailing list archive at Nabble.com. 
> > > > 
> > > 
> > > 
> > > If you reply to this email, your message will be added to the discussion 
> > below: 
> > > 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4819.html
> > > To unsubscribe from Can I Bind a SolidColor Fill Value?, click here. 
> > > NAML 
> > 
> > 
> > 
> > 
> > 
> > -- 
> > View this message in context: 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4848.html
> > Sent from the Apache Flex Users mailing list archive at Nabble.com. 
> > 
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4854.html
> To unsubscribe from Can I Bind a SolidColor Fill Value?, click here.
> NAML





--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4880.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Can I Bind a SolidColor Fill Value?

Posted by Martin Miko <ma...@gmail.com>.
Hi Chris,

yes, basically the presenter variable defined in the thumb skin is done
like this:

    <fx:Declarations>
        <presenters:SliderView_Presenter id="presenter" />
    </fx:Declarations>

you add these 3 lines, and then use the presenter.buttonColour in the
component where you want to use it.

BR,
Martin Miko


On Thu, Feb 6, 2014 at 10:28 AM, Tintin <19...@googlemail.com>wrote:

> Hi Martin
>
> Would you please explain one last point which I can't quite see. You use
> the following code in the custom HSlider:
>
> // injecting the presenter
>         public function set presenter(p:SliderView_Presenter):void {
>             _presenter = p;
>
>             if (thumbInst)
>                 thumbInst.skin.presenter = _presenter;
>         }
>
> Did you create a property named 'presenter' within the Thumb's skin mxml
> file to pass it the HSlider's presenter class?
>
> I can see that I need to pass the presenter to the Thumb's skin so that I
> can bind my Thumb Rect Fill Color property back to the uint property
> defined in my SliderView_Presenter class, but I can't see quite how.
>
> Thanks
>
> Chris
>
> On 4 Feb 2014, at 18:49, Martin Miko [via Apache Flex Users] wrote:
>
> > Hi Chris,
> >
> > I guess you almost have it working now! :) As you wrote in your previous
> > message, you need to pass the SliderView_Presenter instance all the way
> > from the place where you created it, to the place where you want to use
> it
> > (skin). If you pass that instance all the way to the thumb button's skin,
> > then you can use the data binding exactly in the way you wanted.
> >
> >
> > BR,
> > Martin Miko
> >
> >
> > On Tue, Feb 4, 2014 at 5:49 PM, Tintin <[hidden email]>wrote:
> >
> > > Thank you for your considered replies. I'm starting to get it now.
> > >
> > > It looks as if you are creating a custom HSlider with additional
> properties
> > > named 'presenter' and 'thumbInst'. When the creationComplete event is
> > > called
> > > you pass in the SliderView_Presenter class. When you Set the presenter
> > > property you check to ensure you have an instance of the 'thumb' part
> and
> > > if
> > > you do then you assign thumbInst.skin.presenter the instance of
> > > SliderView_Presenter (this must have to be the same instance and not
> > > instantiate a new instance otherwise when a property in the original
> > > SliderView_Presenter class changes the skin will not see this change?).
> > >
> > > This looks to me as if I first need to create a property within the
> thumb
> > > skin named 'presenter' so that I can set it with the
> SliderView_Property
> > > instance I'm passing in?
> > >
> > > In my SliderView_Presenter class I assign a property named
> buttonColour a
> > > uint value by default and when a parameter is passed in from the host
> web
> > > page a simple switch function assigns the correct colour depending on
> the
> > > parameter value passed in. How can I use this to update, say a
> rectangle,
> > > in
> > > my skin please?
> > >
> > > Chris
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4811.html
> > > Sent from the Apache Flex Users mailing list archive at Nabble.com.
> > >
> >
> >
> > If you reply to this email, your message will be added to the discussion
> below:
> >
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4819.html
> > To unsubscribe from Can I Bind a SolidColor Fill Value?, click here.
> > NAML
>
>
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4848.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Can I Bind a SolidColor Fill Value?

Posted by Tintin <19...@googlemail.com>.
Hi Martin

Would you please explain one last point which I can't quite see. You use the following code in the custom HSlider:

// injecting the presenter 
        public function set presenter(p:SliderView_Presenter):void { 
            _presenter = p; 

            if (thumbInst) 
                thumbInst.skin.presenter = _presenter; 
        } 

Did you create a property named 'presenter' within the Thumb's skin mxml file to pass it the HSlider's presenter class?

I can see that I need to pass the presenter to the Thumb's skin so that I can bind my Thumb Rect Fill Color property back to the uint property defined in my SliderView_Presenter class, but I can't see quite how.

Thanks

Chris

On 4 Feb 2014, at 18:49, Martin Miko [via Apache Flex Users] wrote:

> Hi Chris, 
> 
> I guess you almost have it working now! :) As you wrote in your previous 
> message, you need to pass the SliderView_Presenter instance all the way 
> from the place where you created it, to the place where you want to use it 
> (skin). If you pass that instance all the way to the thumb button's skin, 
> then you can use the data binding exactly in the way you wanted. 
> 
> 
> BR, 
> Martin Miko 
> 
> 
> On Tue, Feb 4, 2014 at 5:49 PM, Tintin <[hidden email]>wrote: 
> 
> > Thank you for your considered replies. I'm starting to get it now. 
> > 
> > It looks as if you are creating a custom HSlider with additional properties 
> > named 'presenter' and 'thumbInst'. When the creationComplete event is 
> > called 
> > you pass in the SliderView_Presenter class. When you Set the presenter 
> > property you check to ensure you have an instance of the 'thumb' part and 
> > if 
> > you do then you assign thumbInst.skin.presenter the instance of 
> > SliderView_Presenter (this must have to be the same instance and not 
> > instantiate a new instance otherwise when a property in the original 
> > SliderView_Presenter class changes the skin will not see this change?). 
> > 
> > This looks to me as if I first need to create a property within the thumb 
> > skin named 'presenter' so that I can set it with the SliderView_Property 
> > instance I'm passing in? 
> > 
> > In my SliderView_Presenter class I assign a property named buttonColour a 
> > uint value by default and when a parameter is passed in from the host web 
> > page a simple switch function assigns the correct colour depending on the 
> > parameter value passed in. How can I use this to update, say a rectangle, 
> > in 
> > my skin please? 
> > 
> > Chris 
> > 
> > 
> > 
> > -- 
> > View this message in context: 
> > http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4811.html
> > Sent from the Apache Flex Users mailing list archive at Nabble.com. 
> > 
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4819.html
> To unsubscribe from Can I Bind a SolidColor Fill Value?, click here.
> NAML





--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4848.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Martin Miko <ma...@gmail.com>.
Hi Chris,

I guess you almost have it working now! :) As you wrote in your previous
message, you need to pass the SliderView_Presenter instance all the way
from the place where you created it, to the place where you want to use it
(skin). If you pass that instance all the way to the thumb button's skin,
then you can use the data binding exactly in the way you wanted.


BR,
Martin Miko


On Tue, Feb 4, 2014 at 5:49 PM, Tintin <19...@googlemail.com>wrote:

> Thank you for your considered replies. I'm starting to get it now.
>
> It looks as if you are creating a custom HSlider with additional properties
> named 'presenter' and 'thumbInst'. When the creationComplete event is
> called
> you pass in the SliderView_Presenter class. When you Set the presenter
> property you check to ensure you have an instance of the 'thumb' part and
> if
> you do then you assign thumbInst.skin.presenter the instance of
> SliderView_Presenter (this must have to be the same instance and not
> instantiate a new instance otherwise when a property in the original
> SliderView_Presenter class changes the skin will not see this change?).
>
> This looks to me as if I first need to create a property within the thumb
> skin named 'presenter' so that I can set it with the SliderView_Property
> instance I'm passing in?
>
> In my SliderView_Presenter class I assign a property named buttonColour a
> uint value by default and when a parameter is passed in from the host web
> page a simple switch function assigns the correct colour depending on the
> parameter value passed in. How can I use this to update, say a rectangle,
> in
> my skin please?
>
> Chris
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4811.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Tintin <19...@googlemail.com>.
Thank you for your considered replies. I'm starting to get it now.

It looks as if you are creating a custom HSlider with additional properties
named 'presenter' and 'thumbInst'. When the creationComplete event is called
you pass in the SliderView_Presenter class. When you Set the presenter
property you check to ensure you have an instance of the 'thumb' part and if
you do then you assign thumbInst.skin.presenter the instance of
SliderView_Presenter (this must have to be the same instance and not
instantiate a new instance otherwise when a property in the original
SliderView_Presenter class changes the skin will not see this change?).

This looks to me as if I first need to create a property within the thumb
skin named 'presenter' so that I can set it with the SliderView_Property
instance I'm passing in?

In my SliderView_Presenter class I assign a property named buttonColour a
uint value by default and when a parameter is passed in from the host web
page a simple switch function assigns the correct colour depending on the
parameter value passed in. How can I use this to update, say a rectangle, in
my skin please?

Chris



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4811.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Martin Miko <ma...@gmail.com>.
Hi Chris,

first of all, I see what you are trying to do, but obviously I failed to
explain it clearly.

There are 2 important things you need to realize:

First, declaring a variable in mxml like:

    <fx:Declarations>
        <presenters:SliderView_Presenter id="presenter" />
    </fx:Declarations>

is equal to:

var presenter:SliderView_Presenter = new SliderView_Presenter();

so you need to reassing it to work properly, but I guess we are clear about
this part now.

Second thing you need to understand is the structure of components and
skins:

very rough representation in pseudo mxml:

<HSlider>
    <skin>
        //UI components of the HSlider skin
        <Button id="thumb">
            <skin>
              // UI components of the HSlider Thumb skin
            </skin>
        </Button>
    </skin>
</HSlider>

hope it's not confusing, but this is roughly what you'd have to do, if
you'd want to declared it in one mxml file
without the skinning machinery that does it for you.

This should give you a rough idea, of how things are structured and that,
if you need to pass an instance of
your presenter from your app, you need to pass it at least through a custom
HSlider, to be able to reach the
skin object, where you want to use it. I provided a code snippet from my
custom HSlider implementation.

If you want or need it, I can make you a demo app with comments, but I'm a
bit busy atm, so you'll have to
wait for a while.


> 1. My SliderView_Presenter class is passed a parameter from the host html
> page which determines the button colour. I could declare a variable of Type
> sparkSkin and using a switch function set this to one of several predefined
> skins depending on the parameter passed in. This variable could be bound to
> the skinClass property of the HSlider. This keeps everything within
> SliderView which is bound to SliderView_Presenter.
>
Might be doable, but imo too complicated.



> 2. My skin definition could change the colour of the Thumb graphic if it
> could be bound, or be passed, the parameter when set in
> SliderView_Presenter.
>
If I understand what you want to pass and where it should be passed, this
is exactly what I tried
to demonstrate and explain, but obviously horribly failed at it. :)



> Could I use a CSS Style and get/set the value? Skins are new to me and I'm
> floundering a little!

AFAIK this is not possible. Or at least not possible as a plain CSS
declaration in a .css file.
It might be doable by accessing component's CSSStyleDeclaration [1], but I
wouldn't go into that.
Seems a bit messy to me, but feel free to try it out.

[1]
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/CSSStyleDeclaration.html
horribly

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Evyatar Ben Halevi-Arbib <ev...@gmail.com>.
Maybe in the HSlider skin's updateDisplayList override function you can
call a setStyle function on the Thumb component and then in the Thumb skin
set the color by calling getStyle using the same style name (also in
the skin's updateDisplayList override function)...

Evyatar


On Tue, Feb 4, 2014 at 11:59 AM, Tintin <19...@googlemail.com>wrote:

> ...and an HSlider Thumb is a skin within a skin!
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4797.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Tintin <19...@googlemail.com>.
...and an HSlider Thumb is a skin within a skin!



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4797.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Martin Miko <ma...@gmail.com>.
@Evyatar:

would be doable, as easy as this, as long as it wasn't a skin inside a
skin... this makes it a bit tricky.

Martin Miko


On Mon, Feb 3, 2014 at 9:48 PM, Evyatar Ben Halevi-Arbib <
evyatarbh@gmail.com> wrote:

> You can extend HSlider, add a selectionColor property to it, define the
> custom component as the host component of your skin and then you can access
> the property from the skin using "hostComponent.selectionColor".
>
> Good luck,
> Evyatar
>
>
> On Mon, Feb 3, 2014 at 6:08 PM, Tintin <1955.mille.miglia@googlemail.com
> >wrote:
>
> > OK, I'm back on it.
> >
> > Can I be clear about my scenario. I have a very simple 'view' item (named
> > SliderView) which includes a SWFObject and a Spark HSlider beneath it. I
> > want the button on my HSlider to change colour depending on a value in
> the
> > presenter actionscript file (named SliderView_Presenter). Here's the top
> of
> > my SliderView mxml file:
> >
> > <s:Group
> >         xmlns:fx="http://ns.adobe.com/mxml/2009"
> >         xmlns:s="library://ns.adobe.com/flex/spark"
> >         xmlns:mx="library://ns.adobe.com/flex/mx"
> >         xmlns:presenters="presenters.*"
> >         creationComplete="presenter.onCreationComplete(event)">
> >
> >     <fx:Declarations>
> >
> >         <presenters:SliderView_Presenter id="presenter" />
> >     </fx:Declarations>
> >
> > I have created a Skin for the HSlider (named SliderSkin) and set the
> > skinClass property accordingly.
> >
> > As I see it I could approach this in a few ways:
> >
> > 1. My SliderView_Presenter class is passed a parameter from the host html
> > page which determines the button colour. I could declare a variable of
> Type
> > sparkSkin and using a switch function set this to one of several
> predefined
> > skins depending on the parameter passed in. This variable could be bound
> to
> > the skinClass property of the HSlider. This keeps everything within
> > SliderView which is bound to SliderView_Presenter.
> >
> > 2. My skin definition could change the colour of the Thumb graphic if it
> > could be bound, or be passed, the parameter when set in
> > SliderView_Presenter.
> >
> > Could I use a CSS Style and get/set the value? Skins are new to me and
> I'm
> > floundering a little!
> >
> > Chris
> >
> >
> >
> > --
> > View this message in context:
> >
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4777.html
> > Sent from the Apache Flex Users mailing list archive at Nabble.com.
> >
>

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Tintin <19...@googlemail.com>.
That sounds straightforward, good suggestion I'll have a look at that.

Will the skin be notified of a property change after its creation? The
default property value in my SliderView_Presenter for the Thumb colour will
change as soon as the host web page passes in a parameter. I would like the
Thumb button to change to match the parameter received.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4790.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Evyatar Ben Halevi-Arbib <ev...@gmail.com>.
You can extend HSlider, add a selectionColor property to it, define the
custom component as the host component of your skin and then you can access
the property from the skin using "hostComponent.selectionColor".

Good luck,
Evyatar


On Mon, Feb 3, 2014 at 6:08 PM, Tintin <19...@googlemail.com>wrote:

> OK, I'm back on it.
>
> Can I be clear about my scenario. I have a very simple 'view' item (named
> SliderView) which includes a SWFObject and a Spark HSlider beneath it. I
> want the button on my HSlider to change colour depending on a value in the
> presenter actionscript file (named SliderView_Presenter). Here's the top of
> my SliderView mxml file:
>
> <s:Group
>         xmlns:fx="http://ns.adobe.com/mxml/2009"
>         xmlns:s="library://ns.adobe.com/flex/spark"
>         xmlns:mx="library://ns.adobe.com/flex/mx"
>         xmlns:presenters="presenters.*"
>         creationComplete="presenter.onCreationComplete(event)">
>
>     <fx:Declarations>
>
>         <presenters:SliderView_Presenter id="presenter" />
>     </fx:Declarations>
>
> I have created a Skin for the HSlider (named SliderSkin) and set the
> skinClass property accordingly.
>
> As I see it I could approach this in a few ways:
>
> 1. My SliderView_Presenter class is passed a parameter from the host html
> page which determines the button colour. I could declare a variable of Type
> sparkSkin and using a switch function set this to one of several predefined
> skins depending on the parameter passed in. This variable could be bound to
> the skinClass property of the HSlider. This keeps everything within
> SliderView which is bound to SliderView_Presenter.
>
> 2. My skin definition could change the colour of the Thumb graphic if it
> could be bound, or be passed, the parameter when set in
> SliderView_Presenter.
>
> Could I use a CSS Style and get/set the value? Skins are new to me and I'm
> floundering a little!
>
> Chris
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4777.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Tintin <19...@googlemail.com>.
OK, I'm back on it.

Can I be clear about my scenario. I have a very simple 'view' item (named
SliderView) which includes a SWFObject and a Spark HSlider beneath it. I
want the button on my HSlider to change colour depending on a value in the
presenter actionscript file (named SliderView_Presenter). Here's the top of
my SliderView mxml file:

<s:Group
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        xmlns:presenters="presenters.*"
        creationComplete="presenter.onCreationComplete(event)">

    <fx:Declarations>
        
        <presenters:SliderView_Presenter id="presenter" />
    </fx:Declarations>

I have created a Skin for the HSlider (named SliderSkin) and set the
skinClass property accordingly.

As I see it I could approach this in a few ways:

1. My SliderView_Presenter class is passed a parameter from the host html
page which determines the button colour. I could declare a variable of Type
sparkSkin and using a switch function set this to one of several predefined
skins depending on the parameter passed in. This variable could be bound to
the skinClass property of the HSlider. This keeps everything within
SliderView which is bound to SliderView_Presenter.

2. My skin definition could change the colour of the Thumb graphic if it
could be bound, or be passed, the parameter when set in
SliderView_Presenter.

Could I use a CSS Style and get/set the value? Skins are new to me and I'm
floundering a little!

Chris



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4777.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Martin Miko <ma...@gmail.com>.
You're welcome, feel free to ask what's not clear and I'll try to explain
it.

BR,
Martin


On Sat, Feb 1, 2014 at 7:22 PM, Tintin <19...@googlemail.com>wrote:

> Thanks for your interesting reply.
>
> I'll get back to you shortly to follow this up. Hectic in the studio
> currently but I didn't want to ignore your reply.
>
> Thanks
>
> Chris
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4739.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Tintin <19...@googlemail.com>.
Thanks for your interesting reply.

I'll get back to you shortly to follow this up. Hectic in the studio
currently but I didn't want to ignore your reply.

Thanks

Chris



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4739.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Martin Miko <ma...@gmail.com>.
Hi Chris,

I have a bad feeling you are passing the instance of your presenter in a
wrong way, can you show me the code that is responsible for injecting the
presenter?

Btw my code looks roughly like this:

public class CustomHSlider extends HSlider
{

        private var thumbInst:Object;

        private var _presenter:SliderView_Presenter;

        // injecting the presenter
        public function set presenter(p:SliderView_Presenter):void {
            _presenter = p;

            if (thumbInst)
                thumbInst.skin.presenter = _presenter;
        }

       // here I'm catching the instance of the thumb butto, so I can set
the presenter later,
       // when I assign it from outside
       override protected function partAdded(partName:String,
instance:Object):void {
            if (partName == "thumb") {
                thumbInst = instance;
            }
        }
}

and then I inject the actual instance of presenter I want to work with from
creation complete of this CustomHSlider:

            protected function
customSlider_creationCompleteHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub
                p = new SliderView_Presenter();
                customSlider.presenter = p;
            }

this works for me... I have slightly modified version of your presenter, I
can call the set setButtonColour() directly on it (for the sake of testing) and
it works fine.

The catch is that inside <fx:Declarations> an instance of your Presenter
will be auto-created (default behaviour). Unless you pass your presenter
instance properly, it won't "overlay" this default instance and your
bindings will not work, however nothing will crash. :) I'd like to see how
or more precisely at what point you are setting this instance to the
HSlider/Thumb component, because that might explain why it doesn't work.

If something's unclear, just ask and I'll try to explain it more.

Br,
Martin


On Mon, Jan 27, 2014 at 7:38 PM, Maurice Amsellem <
maurice.amsellem@systar.com> wrote:

> Do you have a compiler warning such as "Cannot bind to ButtonColor"
> because presenter is not EventDispatcher ?
>
> That could be the reason.
>
> Other than that, the code seems good.
>
> Also, did you try having only the ButtonColor prop [Bindable], not the
> whole class?
>
> Maurice
>
> -----Message d'origine-----
> De : Tintin [mailto:1955.mille.miglia@googlemail.com]
> Envoyé : lundi 27 janvier 2014 08:59
> À : users@flex.apache.org
> Objet : Re: RE:Can I Bind a SolidColor Fill Value?
>
> Hi Martin
>
> Let's have another go at displaying the code:
> I have declared my presenter Class as [Bindable]. In my presenter I have a
> property as follows:
>
> internal var _ButtonColour:uint = 0x000000;
>
>     public function get ButtonColour():uint {
>         return _ButtonColour;
>     }
>
>     public function set ButtonColour(value:uint):void {
>         _ButtonColour = value;
>     }
>
>
> I have a Switch statement to change the value depending on the value of
> another property which may change:
>
>     private function setButtonColour():void
>     {
>         trace("setButtonColour called. ButtonColour = " +
> String(ButtonColour));
>         switch(LessonType)
>         {
>             case "purpose":
>                 ButtonColour = 0x24c07f;
>                 break;
>             case "components":
>                 ButtonColour = 0x53c7c7;
>                 break;
>             case "locate":
>                 ButtonColour = 0x88b9ff;
>                 break;
>             case "process":
>                 ButtonColour = 0xab8ff2;
>                 break;
>             case "safetycase":
>                 ButtonColour = 0xe380fe;
>                 break;
>             case "interlocks":
>                 ButtonColour = 0xf187c5;
>                 break;
>             case "safetyfeatures":
>                 ButtonColour = 0xfe6856;
>                 break;
>             case "interrelation":
>                 ButtonColour = 0xff8233;
>                 break;
>             case "opex":
>                 ButtonColour = 0xf99c38;
>                 break;
>             case "other":
>                 ButtonColour = 0xf5d846;
>                 break;
>             default:
>                 ButtonColour = 0x7ab73e;
>                 break;
>             }
>         trace("ButtonColour set to " + String(ButtonColour));
>         }
>
>
> In my mxml file I have defined a Rectangle as follows:
>
> <s:Graphic
>         xmlns:fx="http://ns.adobe.com/mxml/2009"
>         xmlns:s="library://ns.adobe.com/flex/spark"
>         xmlns:presenters="presenters.*">
>
>     <fx:Declarations>
>
>         <presenters:SliderView_Presenter id="presenter" />
>     </fx:Declarations>
>
>     <s:Rect
>             id="BtnColour"
>             width="24" height="24"
>             radiusX="12" radiusY="12">
>
>         <s:fill>
>             <s:SolidColor color="{presenter.ButtonColour}" />
>         </s:fill>
>
>     </s:Rect>
>
> </s:Graphic>
>
> To recap, my presenter class has the [Bindable] meta tag above the Class
> definition. My view includes an HSlider which sets the skinClass =
> SliderSkin. The SliderSkin skin class defines the Thumb button and sets its
> skinClass to SliderThumbSkin.
>
> In my SliderThumbSkin I want to bind the colour of an element in the
> button definition (a Rect with a Fill of solidColour) to a value in my
> presenter class.
>
> The presenter class would be instantiated by the hostComponent, the
> HSlider, so I'm wondering if I should access the property through this.
> Currently my colour property in the presenter is set its initial value and
> the button is set to this colour, when the colour value changes though the
> button does not get notified and does not change.
>
> Does that help?
>
> Chris
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4633.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

RE: RE:Can I Bind a SolidColor Fill Value?

Posted by Maurice Amsellem <ma...@systar.com>.
Do you have a compiler warning such as "Cannot bind to ButtonColor" because presenter is not EventDispatcher ?

That could be the reason. 

Other than that, the code seems good.

Also, did you try having only the ButtonColor prop [Bindable], not the whole class?

Maurice 

-----Message d'origine-----
De : Tintin [mailto:1955.mille.miglia@googlemail.com] 
Envoyé : lundi 27 janvier 2014 08:59
À : users@flex.apache.org
Objet : Re: RE:Can I Bind a SolidColor Fill Value?

Hi Martin

Let's have another go at displaying the code:
I have declared my presenter Class as [Bindable]. In my presenter I have a property as follows: 

internal var _ButtonColour:uint = 0x000000; 

    public function get ButtonColour():uint { 
        return _ButtonColour; 
    } 

    public function set ButtonColour(value:uint):void { 
        _ButtonColour = value; 
    } 


I have a Switch statement to change the value depending on the value of another property which may change: 

    private function setButtonColour():void 
    { 
        trace("setButtonColour called. ButtonColour = " + String(ButtonColour)); 
        switch(LessonType) 
        { 
            case "purpose": 
                ButtonColour = 0x24c07f; 
                break; 
            case "components": 
                ButtonColour = 0x53c7c7; 
                break; 
            case "locate": 
                ButtonColour = 0x88b9ff; 
                break; 
            case "process": 
                ButtonColour = 0xab8ff2; 
                break; 
            case "safetycase": 
                ButtonColour = 0xe380fe; 
                break; 
            case "interlocks": 
                ButtonColour = 0xf187c5; 
                break; 
            case "safetyfeatures": 
                ButtonColour = 0xfe6856; 
                break; 
            case "interrelation": 
                ButtonColour = 0xff8233; 
                break; 
            case "opex": 
                ButtonColour = 0xf99c38; 
                break; 
            case "other": 
                ButtonColour = 0xf5d846; 
                break; 
            default: 
                ButtonColour = 0x7ab73e; 
                break; 
            } 
        trace("ButtonColour set to " + String(ButtonColour)); 
        } 


In my mxml file I have defined a Rectangle as follows: 

<s:Graphic 
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:presenters="presenters.*">

    <fx:Declarations>
        
        <presenters:SliderView_Presenter id="presenter" />
    </fx:Declarations>

    <s:Rect 
            id="BtnColour" 
            width="24" height="24" 
            radiusX="12" radiusY="12">

        <s:fill>
            <s:SolidColor color="{presenter.ButtonColour}" />
        </s:fill>

    </s:Rect>

</s:Graphic>

To recap, my presenter class has the [Bindable] meta tag above the Class definition. My view includes an HSlider which sets the skinClass = SliderSkin. The SliderSkin skin class defines the Thumb button and sets its skinClass to SliderThumbSkin.

In my SliderThumbSkin I want to bind the colour of an element in the button definition (a Rect with a Fill of solidColour) to a value in my presenter class.

The presenter class would be instantiated by the hostComponent, the HSlider, so I'm wondering if I should access the property through this. Currently my colour property in the presenter is set its initial value and the button is set to this colour, when the colour value changes though the button does not get notified and does not change.

Does that help?

Chris



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4633.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Tintin <19...@googlemail.com>.
Hi Martin

Let's have another go at displaying the code:
I have declared my presenter Class as [Bindable]. In my presenter I have a
property as follows: 

internal var _ButtonColour:uint = 0x000000; 

    public function get ButtonColour():uint { 
        return _ButtonColour; 
    } 

    public function set ButtonColour(value:uint):void { 
        _ButtonColour = value; 
    } 


I have a Switch statement to change the value depending on the value of
another property which may change: 

    private function setButtonColour():void 
    { 
        trace("setButtonColour called. ButtonColour = " +
String(ButtonColour)); 
        switch(LessonType) 
        { 
            case "purpose": 
                ButtonColour = 0x24c07f; 
                break; 
            case "components": 
                ButtonColour = 0x53c7c7; 
                break; 
            case "locate": 
                ButtonColour = 0x88b9ff; 
                break; 
            case "process": 
                ButtonColour = 0xab8ff2; 
                break; 
            case "safetycase": 
                ButtonColour = 0xe380fe; 
                break; 
            case "interlocks": 
                ButtonColour = 0xf187c5; 
                break; 
            case "safetyfeatures": 
                ButtonColour = 0xfe6856; 
                break; 
            case "interrelation": 
                ButtonColour = 0xff8233; 
                break; 
            case "opex": 
                ButtonColour = 0xf99c38; 
                break; 
            case "other": 
                ButtonColour = 0xf5d846; 
                break; 
            default: 
                ButtonColour = 0x7ab73e; 
                break; 
            } 
        trace("ButtonColour set to " + String(ButtonColour)); 
        } 


In my mxml file I have defined a Rectangle as follows: 

<s:Graphic 
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:presenters="presenters.*">

    <fx:Declarations>
        
        <presenters:SliderView_Presenter id="presenter" />
    </fx:Declarations>

    <s:Rect 
            id="BtnColour" 
            width="24" height="24" 
            radiusX="12" radiusY="12">

        <s:fill>
            <s:SolidColor color="{presenter.ButtonColour}" />
        </s:fill>

    </s:Rect>

</s:Graphic>

To recap, my presenter class has the [Bindable] meta tag above the Class
definition. My view includes an HSlider which sets the skinClass =
SliderSkin. The SliderSkin skin class defines the Thumb button and sets its
skinClass to SliderThumbSkin.

In my SliderThumbSkin I want to bind the colour of an element in the button
definition (a Rect with a Fill of solidColour) to a value in my presenter
class.

The presenter class would be instantiated by the hostComponent, the HSlider,
so I'm wondering if I should access the property through this. Currently my
colour property in the presenter is set its initial value and the button is
set to this colour, when the colour value changes though the button does not
get notified and does not change.

Does that help?

Chris



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4633.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Martin Miko <ma...@gmail.com>.
Hi Chris,

sorry, but no code so far.

given what you said I think you are missing one [Bindable] meta tag

let's say you have following class

public class Foo {
    [Bindable]
    public var color:uint = 0x0;

    public function setColor():void {
        color = 0xaaaaaa;
    }
}

now in your view you need to declare a bindable variable of type Foo, let's
call it foo

[Bindable]
private var foo:Foo = new Foo();

having this you can bind you Rectangle's SolidColor's color to "foo.color"

by calling method setColor() you will change it's color from black to grey.

Simple working example can be found here: class Foo [1] Simple App view
with rectangle [2]. Hope it helps.

[1] http://pastebin.com/Ghqtg5NF
[2] http://pastebin.com/nCf8DJ6v


Martin Miko


On Sun, Jan 26, 2014 at 1:25 PM, Tintin <19...@googlemail.com>wrote:

> Can you see the code now?
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4620.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: RE:Can I Bind a SolidColor Fill Value?

Posted by Tintin <19...@googlemail.com>.
Can you see the code now?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615p4620.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE:Can I Bind a SolidColor Fill Value?

Posted by Maurice Amsellem <ma...@systar.com>.
Source code bas been stripped.  Use text only
________________________________________
De : Tintin [1955.mille.miglia@googlemail.com]
Envoyé : samedi 25 janvier 2014 21:22
À : users@flex.apache.org
Objet : Can I Bind a SolidColor Fill Value?

Hello

I have defined a Spark Rect and want to bind its fill value to a property in
a presenter file, is this possible?

I have declared my presenter Class as [Bindable]. In my presenter I have a
property as follows:


I have a Switch statement to change the value depending on the value of
another property which may change:


In my mxml file I have defined a Rectangle as follows:


Frustratingly my rectangle remains black even though I know the Switch
statement is working, as initially set in the class. I'm sure there's a
'schoolboy error' somewhere but I can't see it!

Regards

Chris



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-I-Bind-a-SolidColor-Fill-Value-tp4615.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.