This is really bizarre. For some reason the bindings get updated three times when you use Object, but only two times, when you use Class as the return type. Strange ...

Cheers,
Ralf.

On 7/18/06, Tobias Patton <[EMAIL PROTECTED]> wrote:

Hello Flexcoders;

 

I'm hoping someone can help me understand what's going on here.

 

I have a custom component that subclasses Canvas. It works much list a List in that it uses a dataProvider to pass a data object to child object (item renderer). The child objects render the data object in some appropriate manner. One of the item renderers is very simple – an image with some text below it. The image displayed is chosen from a number of embedded images based on a property of the data object.

 

The image object looks like:

 

<mx:Image source="{GetImage( MyObject( data ).kind}"/>

 

And there is a function in the Script section:

 

private function GetImage( kind : uint ) : Class

{

     if( kind == 0 )

     {

           return image1;
     }

     else …
}

 

This does not work. The source parameter of the Image object is never populated. In fact, the GetImage() function is never called with a non-null value!

 

There is a workaround, but I'm truly at a loss to explain why it works. If the GetImage() function is changed to return Object instead of Class, everything works as expected. Since Class is a subclass of Object, the up-cast is automatic and no other changes are required.  With this change in place, the GetImage() function is called initially with null, but later with a real value.

 

How could the return value of a function change the way binding operates?

 

I've attached some simple code at the end of this email that reproduces the problem with the minimal work. If someone has an explanation for what's going on here, I'd be very grateful.

 

Thanks.

Tobias.

 

Kodak Graphic Communications Canada Company

Tobias Patton | Software Developer | Tel: +1.604.451.2700 ext: 5148 | mailto:[EMAIL PROTECTED] | http://www.creo.com

--------- ImageBinding.mxml ---------

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"

            layout="vertical"

            xmlns:local="*">

           

            <local:MyData id="myData" num="3"/>

           

            <mx:Canvas backgroundColor="0xffffff" width="300" height="100">

                        <local:ImageBox data="">

            </mx:Canvas>

</mx:Application>

 

--------- ImageBox.mxml ---------

 

<?xml version="1.0" encoding="utf-8"?>

<mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="75" height="75">

            <mx:Script>

                        <![CDATA[

                       

                                    //private function GetImageForData( val : MyData ) : Object                            

                                    private function GetImageForData( val : MyData ) : Class

                                    {

                                                trace( "GetImageForData", val ? val.num : "null" );

                                                return ( val.num % 2 ) ? m_image : m_image2;

                                    }

                                   

                                    [ Embed( "image.png" ) ]

                                    private static const m_image : Class;

                                   

                                    [ Embed( "image2.png" ) ]

                                    private static const m_image2 : Class;

                        ]]>

            </mx:Script>

           

            <mx:Image source="{GetImageForData( MyData( data ) )}"/>

</mx:VBox>

 

--------- MyData.as ---------

 

package

{

public class MyData

{

            [ Bindable ]

            public var num : Number;

}

}

 




--
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany __._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to