----- Original Message ----- 
From: "fred44455" <[email protected]>
To: <[email protected]>
Sent: Monday, March 16, 2009 3:01 AM
Subject: [flexcoders] Simple actionscript that I cannot understand! Please 
help. Thanks


>
>
> <?xml version="1.0"?>
> Can somebody explain into details what that code do?(line by line). I know 
> that it is changing the font size but I cannot understand the :"s"
> and the "normal"? I understand the overal code but not everything. Thanks 
> again for your time. Fred.

The buttons in the application are called myButton1 and myButton2.

To change the style of a button changeLabel() is called  with the button 
number supplied as a string s.

Inside changeLabel s is changed to be the actual name of the button - e.g. 
"myButton"+ "1" becomes "myButton1".

String s is the name of the button whose style we need to work with. 
this[s] refers to the actual button.

"this" is the current object instance and in this context it is the 
application container. the [s] refers to an attribute of that object named 
"s" and returns a reference to the attribute.
In this case this[s] returns a reference to the button whose name is 
contained in the string s.

Paul

> <!-- usingas/FlexComponents.mxml -->
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>
>  <mx:Script><![CDATA[
>    private var newFontStyle:String;
>    private var newFontSize:int;
>
>    public function changeLabel(s:String):void {
>        s = "myButton" + s;
>
>        if (this[s].getStyle("fontStyle")=="normal") {
>            newFontStyle = "italic";
>            newFontSize = 18;
>        } else {
>            newFontStyle = "normal";
>            newFontSize = 10;
>        }
>
>        this[s].setStyle("fontStyle",newFontStyle);
>        this[s].setStyle("fontSize",newFontSize);
>    }
>    ]]></mx:Script>
>
>    <mx:Button id="myButton1"
>        click="changeLabel('2')"
>        label="Change Other Button's Styles"
>    />
>    <mx:Button id="myButton2"
>        click="changeLabel('1')"
>        label="Change Other Button's Styles"
>    />
> </mx:Application>
>
>
>
>
> ------------------------------------
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Alternative FAQ location: 
> https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
> Search Archives: 
> http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups 
> Links
>
>
>

Reply via email to