【正文】
用戶的操作和其它情況采取不同的工作方式。這些功能使 Flash 不僅功能強大,而且易于使用。 3 使用 Flash 可以做什么 使用 Flash 中的諸多功能,可以創(chuàng)建許多類型的應用程序。游戲通常結合了 Flash 的動畫功能和 ActionScript 的邏輯功能。餐廳 Web 站點上的靈活消息區(qū)域 (FMA) 可能顯示每天的特價菜單。隨著對 Flash 及其工作流程的不斷熟悉,您會發(fā)現(xiàn)一種最適合自己的工作方式。 事件發(fā)生時,您應編寫一個事件處理函數(shù),從而在該事件發(fā)生時讓一個動作響應該事件。例如,當用戶滑過一個按鈕時,將發(fā)生 或 on(rollOver) 事件;當用戶單擊某個按鈕時,將發(fā)生 事件;如果按下鍵盤上的某個鍵,則發(fā)生 on(keyPress) 事件。 7 幀事件 在主時間軸或影片剪輯時間軸上,當播放頭進入關鍵幀時會發(fā)生系統(tǒng)事件 這叫做幀事件。 幀腳本最常見的一種用法是在到達特定的關鍵幀后停止回放。例如,可以使用幀腳本來動態(tài)更新某個標簽的值、管理舞臺上各元素的交互等等。因此,在 Flash 中創(chuàng)建 ActionScript 時遵循編碼最佳做法是非常重要的。 在將所有腳本附加到各個元素時,同時也會將所有代碼嵌入到 FLA 文件中。如果您在與其他開發(fā)人員共同開發(fā)一個項目,外部文件還有助于進行調試和源文件控制管理。 9 關于通過編寫腳本來處理事件 編寫事件代碼可以分為兩大類:在時間軸上(在關鍵幀中)發(fā)生的事件和在對象實例(影片剪輯、按鈕和組件)上發(fā)生的事件。 10 使用 動作 面板和 腳本 窗口 若要在 FLA 文件中創(chuàng)建腳本,可以直接將 ActionScript 輸入 動作 面板。除了 腳本 窗口的代碼幫助功能之外,動作面板還提供了一些其它功能。 the system triggers events when specific conditions are met or processes pleted (the movie loads, the Timeline reaches a certain frame, a graphic finishes downloading, and so on). When an event occurs, you write an event handler to respond to the event with an action. Understanding when and where events occur will help you to determine how and where you will respond to the event with an action, and which ActionScript tools should be used in each case. Events can be grouped into a number of categories: mouse and keyboard events, which occur when a user interacts with your Flash application via the mouse and keyboard。 if a key on the keyboard is pressed, the on (keyPress) event occurs. You can attach scripts to handle these events and add all the interactivity you desire. Clip events Within a movie clip, you may react to a number of clip events that are triggered when the user enters or exits the scene or interacts with the scene using the mouse or keyboard. You might, for example, load an external SWF file or JPG image into the movie clip when the user enters the scene, or allow the user’ s mouse movements to reposition elements in the scene. Frame events On a main or movie clip Timeline, a system event occurs when the playhead enters a keyframe— this is known as a frame event. Frame events are useful for triggering actions based on the passage of time (moving through the Timeline) or for interacting with elements that are currently visible on the stage. When you add a script to a keyframe, it is executed when the keyframe is reached during playback. A script attached to a frame is called a frame script. One of the most mon uses of frame scripts is to stop the playback when a certain keyframe is reached. This is done with the stop() function. You select a keyframe and then add the stop() function as a script element in the Actions panel. Once you’ ve stopped the movie at a certain keyframe, you need to take some action. You could, for example, use a frame script to dynamically update the value of a label, to manage the interaction of elements on the stage, and so on. For more information, see Chapter 5, “ Handling Events,” on page . Organizing ActionScript code You may attach scripts to keyframes and to object instances (movie clips, buttons, and other symbols). However, if your ActionScript code is scattered over many keyframes and object instances, debugging your application will be much more difficult. It will also be impossible to share y