質問

I just started learning Flex these days.. I just had one doubt: below is the code:

Main.mxml

 <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

        <s:layout>

            <s:VerticalLayout paddingLeft="10" paddingTop="10"/>
        </s:layout>

        <fx:Style source="Styles.css" />

        <fx:Script>
            <![CDATA[
                import components.NameDisplay;

                import spark.skins.spark.DefaultComplexItemRenderer;
                import spark.skins.spark.DefaultItemRenderer;

                private function rendererFunction(item: Object): ClassFactory
                {
                    if(item is String)
                        return new ClassFactory(NameDisplay);
                    else
                        return new ClassFactory(DefaultComplexItemRenderer);
                }
            ]]>
        </fx:Script>

        <fx:Declarations>

            <s:ArrayList id="employeeList">
                <fx:String>Samuel Ang</fx:String>
                <s:BitmapImage source="images/sang.jpg"/>

                <fx:String>Athena Parker</fx:String>
                <s:BitmapImage source="images/aparker.jpg"/>

                <fx:String>Saul Tucker</fx:String>
                <s:BitmapImage source="images/stucker.jpg"/>

                <fx:String>Alyssa Le</fx:String>
                <s:BitmapImage source="images/ale.jpg"/>
            </s:ArrayList>


        </fx:Declarations>


        <s:Label text="Employee Portal: Employee Directory"
                 styleName="titleHeader"/>

        <s:DataGroup dataProvider="{employeeList}"
                     itemRendererFunction="rendererFunction">

            <s:layout>
                <s:VerticalLayout paddingLeft="15" paddingTop="15"/>
            </s:layout>

        </s:DataGroup>


    </s:Application>

NameDisplay.mxml

 <?xml version="1.0" encoding="utf-8"?>
    <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                    xmlns:s="library://ns.adobe.com/flex/spark" 
                    xmlns:mx="library://ns.adobe.com/flex/mx" 
                    autoDrawBackground="true">
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>

        <s:Label text="{data}"
                 width="74" height="30"
                 backgroundColor="#000000" 
                 color="#FFFFFF" 
                 textAlign="center" 
                 verticalAlign="middle" />

    </s:ItemRenderer>

My Doubts:

1) How does my 'rendererFunction' code returns a ItemRenderer at end? I mean how does ClassFactory returns a ItemRenderer object? I checked ClassFactory.as code, I have seen newInstance() method (which was implemented from IFactory interface), so how does ClassFactory calls automatically newInstance() method (actually, iam guessing that iam getting ItemRenderer object via newInstance() method)

2) Inside DisplayName.mxml code: <s:Label text="{data}" , I found that this 'data' coming from DataRenderer.as , BUT i didnt understood how does it getting value, from where??

3) I heard from many people saying that Flex developed from Java, Is that correct? If yes, why I didnt found not even a single java file inside Flex Source code?

4) now Curretnly, Apache is owner of Flex, so then why does Flex API still showing as 'Adobe'? (asked this just to know myself)

Sorry, if they're stupid queries!

Waiting for replies!

役に立ちましたか?

解決

1) How does my 'rendererFunction' code returns a ItemRenderer at end? I mean how does ClassFactory returns a ItemRenderer object?

I'm not sure what your really asking here, but I'll try. I believe it happens like this:

1) The DataGroup needs an itemRenderer to display some data

2) The DataGroup checks to see if an itemRendererFunction exists. if it does; it calls the function. The function returns a ClassFactory

3) The ClassFactory is used inside the DataGroup to create a new instance. I would assume that the newInstance() method is called; but I am not reviewing the code to write this.

4) The DataGroup sets the data property on the new renderer instance. I assume it also stores the renderer instance somewhere.

5) The renderer instance is added as a child of the DataGroup

At the end of the day; you'll have to delve into the Flex Framework code to figure out the answers to your questions.

2) Inside DisplayName.mxml code:

The DataGroup will set the data property on the renderer. It relates to an item from the DataGroup's dataProvider.

3) I heard from many people saying that Flex developed from Java, Is that correct? If yes, why I didnt found not even a single java file inside Flex Source code?

The Flex compiler is built in Java. The Flex Framework is all ActionScript.

4) now Curretnly, Apache is owner of Flex, so then why does Flex API still showing as 'Adobe'? (asked this just to know myself)

For backward compatibility reasons primarily. I believe the Apache Flex SDK includes new classes which are not in an Adobe namespace.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top