- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
- <mx:Script>
- <![CDATA[
- [Bindable]
- private var scale:Number = 1;
- internal function doResize(n:Number):Number{
- trace(scale);
- zoom.zoomWidthTo = n;
- zoom.play();
- return box.scaleX;
- }
- ]]>
- </mx:Script>
- <mx:Zoom id="zoom" originX="0" originY="0" target="{box}" />
- <mx:HSlider id="slider" x="120" y="301" change="{scale =slider.value}" minimum="0" maximum="1"/>
- <mx:Canvas id="box" styleName="box" x="100" y="56" scaleX="{doResize(scale)}" width="200"
- height="200" backgroundColor="#3FCA69" borderStyle="outset" themeColor="#13496B">
- </mx:Canvas>
- </mx:Application>
这里绑定了一个变量scale,其实绑定就相当于写了一个事件,当数据改变时就派发数据源所在的事件类型。
所以单HSlider改变scale就改变了,scale一改变因为绑定了,所以Canvas的函数也触发了,函数返回的数值,改变Canvas的大小