我们如何从其他.mxml中检索main.mxml上的值?

时间:2010-04-23 05:29:08

标签: flex

main.mxml

        

        [Bindable]
        private var _dp:ArrayCollection = new ArrayCollection([
            {day:"Monday", dailyTill:7792.43},
            {day:"Tuesday", dailyTill:8544.875},
            {day:"Wednesday", dailyTill:6891.432},
            {day:"Thursday", dailyTill:10438.1},
            {day:"Friday", dailyTill:8395.222},
            {day:"Saturday", dailyTill:5467.00},
            {day:"Sunday", dailyTill:10001.5}
        ]);

        public var hx:String ;
        public function init():void
         {
            //parameters is passed to it from flashVars
            //values are either amount or order
            hx = Application.application.parameters.tab;
         }
    ]]>
</mx:Script>


<mx:LineChart
    id="myLC"
    dataProvider="{_dp}"
    showDataTips="true"
    dataTipRenderer="com.Amount"
>
    <mx:horizontalAxis>
        <mx:CategoryAxis categoryField="day" />
    </mx:horizontalAxis>
    <mx:series>
        <mx:LineSeries xField="day" yField="dailyTill">
        </mx:LineSeries>
    </mx:series>
</mx:LineChart>

COM / Amount.mxml

        

        [Bindable]
        private var _dayText:String;

        [Bindable]
        private var _dollarText:String;

        override public function set data(value:Object):void{
            //Alert.show(Application.application.parameters.tab);
            //we know to expect a HitData object from a chart, so let's cast it as such
            //so that there aren't any nasty runtime surprises
            var hd:HitData = value as HitData;

            //Any HitData object carries a reference to the ChartItem that created it.
            //This is where we need to know exactly what kind of Chartitem we're dealing with.
            //Why? Because a pie chart isn't going to have an xValue and a yValue, but things
            //like bar charts, column charts and, in our case, line charts will.
            var item:LineSeriesItem = hd.chartItem as LineSeriesItem;

            //the xValue and yValue are returned as Objects. Let's cast them as strings, so
            //that we can display them in the Label fields.
            _dayText =  String(item.xValue);
            _dollarText = String(item.yValue);
        }//end set data
    ]]>
</mx:Script>

QUES:Amount.mxml用作折线图的dataTipRenderer。现在,我需要从“com / Amount.mxml”获取main.mxml中赋值给变量“hx”的值。非常感谢任何帮助?

1 个答案:

答案 0 :(得分:1)

您无法访问其他mxml文件中的一个mxml中定义的变量,因为这两个文件是单独编译的。并且生成的.swf嵌入在不同的html文件中。所以据我所知,这是不可能的。如果我出错了,请告诉我。

由于

PRASHANT