2012-04-24 126 views

回答

0

下面是一些代码中使用CSS通过Maxim Kachurovskiy

(这是不是我的,部分过时,但它工作得很好):

enter image description here

FontSize.mxml:

<?xml version="1.0" encoding="utf-8"?> 
<!-- (c) Maxim Kachurovskiy --> 
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    addedToStage="addedToStageHandler();" 
    initialize="fontSize = 11;"> 

    <mx:Style> 
     .header { 
      font-weight: bold; 
      fontSizeDelta: 5; 
     } 
    </mx:Style> 

    <mx:Script> 
     <![CDATA[ 
      private var _fontSize:Number; 

      [Bindable("fontSizeChange")] 
      public function get fontSize():Number { 
       return _fontSize; 
      } 

      public function set fontSize(value:Number):void { 
       if (_fontSize == value) 
        return; 

       _fontSize = value; 
       applyFontSize(_fontSize); 
       dispatchEvent(new Event('fontSizeChange')); 
      } 

      private function applyFontSize(fontSize:Number):void { 
       var selectors:Array = StyleManager.selectors; 
       for each (var selector:String in selectors) { 
        var declaration:CSSStyleDeclaration = StyleManager.getStyleDeclaration(selector); 
        var delta:Number = declaration.getStyle('fontSizeDelta'); 
        if (delta) { 
         declaration.setStyle('fontSize', fontSize + delta); 
         StyleManager.setStyleDeclaration(selector, declaration, true); 
        } 
       } 

       var global:CSSStyleDeclaration = StyleManager.getStyleDeclaration('global'); 
       if (!global) 
        global = new CSSStyleDeclaration('global'); 
       global.setStyle('fontSize', fontSize); 
       StyleManager.setStyleDeclaration('global', global, true); 
      } 

      private function addedToStageHandler():void { 
       stage.addEventListener(KeyboardEvent.KEY_UP, my_keyUpHandler); 
      } 

      private function my_keyUpHandler(event:KeyboardEvent):void { 
       if (event.ctrlKey) { 
        var keyCode:uint = event.keyCode; 
        if (keyCode == 107 || keyCode == 187 || keyCode == 38) 
         fontSize++; 
        else if (keyCode == 109 || keyCode == 189 || keyCode == 40) 
         fontSize--; 
       } 
      } 
     ]]> 
    </mx:Script> 

    <mx:Panel title="Font size change" layout="vertical" 
       horizontalCenter="0" verticalCenter="0" paddingBottom="10" 
       paddingLeft="10" paddingRight="10" paddingTop="10"> 
     <mx:HBox horizontalGap="10"> 
      <mx:Label text="Font size:" styleName="header"/> 
      <mx:NumericStepper id="numericStepper" value="{fontSize}" 
       change="{fontSize = numericStepper.value;}" maximum="100" minimum="1"/> 
     </mx:HBox> 
     <mx:Label text="Ctrl+/- adjust font size too."/> 
    </mx:Panel> 
</mx:Application> 
0

这里是增加点击按钮字体大小...查看

<mx:Label id="lb" text="INDIA"/> 
<mx:Button label="change" click="button1_clickHandler(event)"/> 


protected function button1_clickHandler(event:MouseEvent):void 
{ 
    lb.setStyle('fontSize',Number(lb.getStyle('fontSize'))+5); 
} 


lb.setStyle('fontSize',Number(lb.getStyle('fontSize'))+5); 

需要从以前的拉布勒字体值值,增加5,并设置它的代码再次...

您可以直接设置的取以前字号

值instate 210
lb.setStyle('fontSize',Math.random()*200); 
+0

谢谢,在这里寻找增加整个应用程序的大小,而不是单一的控制:) – flex 2012-04-24 18:18:04

0

这可以帮助你......

[Bindable]private var _size:Number = 10; 

protected function button1_clickHandler(event:MouseEvent):void 
{ 
     _size = _size+10; 
} 

<mx:Label id="lb" text="INDIA" fontSize="{_size}"/> 
<mx:Label id="lb1" text="I love India" fontSize="{_size}"/> 

<mx:Button label="change" click="button1_clickHandler(event)" /> 
相关问题