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 <
[email protected]> 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:[email protected]]
> Envoyé : lundi 27 janvier 2014 08:59
> À : [email protected]
> 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.
>