PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : private function


kostonstyle
06.11.2006, 10:24
Hallo miteinander
als ich am flex programmierte, bemerkete ich spontan, dass alle funktion mit private function anfängt, warum?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
viewSourceURL="src/ControlsButtonBased/index.html"
layout="absolute" width="460" height="400"
>
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
import mx.controls.Alert;

private const NL:String = "\r";

private function submitButtonClickHandler (event:MouseEvent):void
{
var userDetails:String = "You submitted the following details:" + NL + NL;
userDetails += "Name: " + userName.text + NL;
userDetails += "Email: " + userEmail.text + NL;
userDetails += "Hide email? " + (hideEmail.selected ? "Yes" : "No") + NL + NL;
userDetails += "Comment:" + NL + NL + userComment.text;

Alert.show (userDetails);
}

private function emailButtonClickHandler (event:MouseEvent):void
{
var msg:String = "You can use the navigateToURL() method to open a URL"
msg += " using a call similar to the following:\r\r";
msg += "navigateToURL (new URLRequest (&apos;mailto:comments@somewhere.com&apos;));";

Alert.show (msg);
}

]]>
</mx:Script>

<mx:Panel
title="Leave a comment"
left="10" top="10" right="10" bottom="10"
layout="absolute"
>
<mx:Text
text="Fill out this form to leave us a comment:"
width="250" x="10" y="10" fontWeight="bold"
/>
<mx:Label text="Name:" x="10" y="38"/>
<mx:TextInput id="userName" y="36" right="10" left="90"/>
<mx:Label text="Email:" x="10" y="68"/>
<mx:TextInput id="userEmail" y="66" right="10" left="90"/>
<mx:Label text="Comment:" x="10" y="129"/>
<mx:TextArea id="userComment" left="10" right="10" height="109" bottom="40"/>

<mx:CheckBox
id="hideEmail"
y="103" left="90"
label="Hide my email address"
selected="true"
/>

<mx:LinkButton
id="emailButton"
y="272" horizontalCenter="0"
label="Having trouble? Email us!"
click="emailButtonClickHandler(event);"
/>

<mx:ControlBar x="120" y="258" horizontalAlign="center">
<mx:Button
id="submitButton" label="Submit"
click="submitButtonClickHandler(event);"
/>
</mx:ControlBar>

</mx:Panel>
</mx:Application>
Danke kostonstyle

elysian
06.11.2006, 11:09
xervus!

nicht alle funktionsdeklarationen beginnen automatisch mit private.
das schlüsselwort vor function bestimmt den "wertebereich" (scope), in dem die function definiert ist. ist eine funktion beispiels als private deklariert, so hat nur die klasse, in der sie definiert wurde, zugriff auf sie. public funktionen dagegen sind über alle klassen hinweg sichtbar.

andere scopes sind public, protected, ... schau mal in der hilfe nach.

cheers, thomas