flex动态改变函数之间的值

时间:2011-06-03 10:33:50

标签: flex actionscript-3 flex4

我有一个主mxml和2个AS类。在主mxml中我有一个slider.I想在移动滑块时获取AS类中的滑块值。

Main.MXML

import First;
import Second;
private var my:First;
privaate var scd:Second;
public var sd:Date; 

public function init():void {
     my = new First();
     Canvas.addChild(my.getUIComponent()); 
}

public function dateChange():Date {
    startDate.selectedDate = new Date(slider.values[0]);
    endDate.selectedDate = new Date(slider.values[1]);
    sd = new Date(slider.values[0]);
    scd.calsldr(sd); 
    return sd;                  
}

<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="top">
<mx:Canvas id="Canvas" backgroundColor="#ffffff" height="600" width="100%"
            horizontalScrollPolicy="off" verticalScrollPolicy="off">
</mx:Canvas>
</mx:HBox>
<flexlib:HSlider id="slider" width="100%" height="50" thumbCount="2"                     lockRegionsWhileDragging="true" allowTrackClick="true" maintainProjectionCenter="true"
                 change="dateChange();" liveDragging="true"
                 thumbSkin="mx.skins.spark.SliderThumbSkin"
                 trackSkin="mx.skins.spark.SliderTrackSkin"
                 trackHighlightSkin="mx.skins.spark.SliderTrackHighlightSkin" />
<mx:HBox x="300" y="300" height="50">
<mx:Label text="Start Date :"/>     <mx:DateField id="startDate"/>
<mx:Label text="End Date"/>     <mx:DateField id="endDate"/>
</mx:HBox>

我的第一个AS是第一个.AS  调用Second.AS

addChild(new Second(str) as Sprite);

str是一个字符串值

我想在Second.AS中使用滑块值    我试过用这个:

public function calsldr(dat:Date):void {
    trace(dat);
}

private function visualization():void{ }

我可以从trace(dat)获取值....我的意思是滑块更改时的日期。 如何在函数可视化()

中使用此更改值

提供帮助。

1 个答案:

答案 0 :(得分:0)

@J_A_X 第二个AS是:

public function Second(str:String){
    name = "Second";    }
public function calsldr(dat:Date){
    trace(dat+"fu in maaka"); // As I change the slider the value is changed here  }
protected override function init():void
    {
        var ldr:URLLoader = new URLLoader(new URLRequest(url));
        _bar.loadURL(ldr, function():void {
        var obj:Array = JSON.decode(ldr.data as String) as Array;
        //Sorted the values based on 'str'
    var data:Data = buildData(newarr);
        visualize(data);
        _bar = null; });
    }
public function visualize(data:Data):void{
      // I want to get the dat values here when ever the slider moves
}