2013-09-23 69 views
0

這是一個腳本,它根據預定義的名稱列表要求並驗證用戶名稱 。從adobe adobe tutorial複製的腳本仍然不能正常工作零結果

我從教程中複製了整個腳本,但結果不算什麼,我甚至不明白爲什麼沒有錯誤!我首先通過複製腳本來學習,然後理解它,但不幸的是,結果沒有任何錯誤!我是新來編程,所以請儘量解釋的事情

腳本框架1:

var myGreeter:Greeter = new Greeter(); 
mainText.text = myGreeter.sayHello("") 

腳本動作腳本文件命名爲招待員:

package 
{ 
public class Greeter 
{ 
/** 
* Defines the names that should receive a proper greeting. 
*/ 
public static var validNames:Array = ["Sammy", "Frank", "Dean"]; 
/** 
* Builds a greeting string using the given name. 
*/ 
public function sayHello(userName:String = ""):String 
{ 
var greeting:String; 
if (userName == "") 
{ 
greeting = "Hello. Please type your user name, and then press the Enter key."; 
} 
else if (validName(userName)) 
{ 
greeting = "Hello, " + userName + "."; 
} 
else 
{ 
greeting = "Sorry, " + userName + ", you are not on the list."; 
} 
return greeting; 
} 
/** 
* Checks whether a name is in the validNames list. 
*/ 
public static function validName(inputName:String = ""):Boolean 
{ 
if (validNames.indexOf(inputName) > -1) 
{ 
return true; 
} 
else 
{ 
return false; 
} 
} 
} 
} 

回答

1

想必你引用Adobe的Getting started with ActionScript: Creating a basic application

這個較舊的教程更適合於Flex 3,其中您將實現一個前端演示文稿以連接到Greeter類。

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" 
    layout="vertical" 
    creationComplete="initApp()"> 

    <mx:Script> 
     <![CDATA[ 
      private var myGreeter:Greeter = new Greeter(); 

      public function initApp():void 
      { 
       // says hello at the start, and asks for the user's name 
       mainTxt.text = myGreeter.sayHello(); 
      } 

     ]]> 
    </mx:Script> 

    <mx:TextArea id="mainTxt" width="400" backgroundColor="#DDDDDD" 
       editable="false"/> 

    <mx:HBox width="400">  
     <mx:Label text="User Name:"/>  
     <mx:TextInput id="userNameTxt" width="100%" 
         enter="mainTxt.text=myGreeter.sayHello(userNameTxt.text);"/> 
    </mx:HBox> 

</mx:Application> 

通過簡單地粘貼Greeter類,你會不會收到,因爲沒有這個類的部分執行錯誤。這個班沒有任何東西被稱爲。

這是一個比較差的教程,並與被日這將是可取去別處尋找教程和例子,如結合: