How can we retrieve value on main.mxml from other .mxml?

Posted by Roshan on Stack Overflow See other posts from Stack Overflow or by Roshan
Published on 2010-04-23T05:29:08Z Indexed on 2010/04/23 5:33 UTC
Read the original article Hit count: 334

Filed under:

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);
            var hx : String = String(item.yValue)
            _dollarText = hx.replace("$"," ");
        }//end set data
    ]]>
</mx:Script>

QUES : Amount.mxml is used as dataTipRenderer for line chart. Now, I need to obtain the value assigned to variable "hx" in main.mxml from "com/Amount.mxml".Any help would be greatly appreciated?

© Stack Overflow or respective owner

Related posts about flex