Creating Custom Context Menus
Số trang: 11
Loại file: pdf
Dung lượng: 32.73 KB
Lượt xem: 15
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Standard menu. Xuất hiện khi bạn kích chuột phải vào bất cứ điều gì trong một bộ phim Flash, ngoại trừ một trường văn bản. Hiệu chỉnh trình đơn. Xuất hiện khi bạn kích chuột phải vào một trường văn bản đó là có thể chỉnh sửa hoặc lựa chọn. Lỗi menu. Xuất hiện khi một bộ phim Flash không tải trong vòng một trang Web và phải bạn nhấp chuột vào vùng trống.
Nội dung trích xuất từ tài liệu:
Creating Custom Context Menus < Day Day Up >Creating Custom Context MenusThe context menu appears when you right-click a Flash movie (Control-click on aMacintosh). There are three different types of Flash context menus: • Standard menu. Appears when you right-click anything in a Flash movie except a text field. • Edit menu. Appears when you right-click a text field thats editable or selectable. • Error menu. Appears when a Flash movie fails to load within a Web page and you right-click in the empty area.The error menu cannot be changed, but the standard and edit context menus can becustomized to display new items or remove the built-in default items. All the built-incontext menu items can be removed except for the Settings item and the Debugger item.The Flash player includes two built-in classes to assist you in creating a customizedcontext menu: • ContextMenu. This class allows you to create a new context menu, hide built-in menu items (Zoom In, Zoom Out, 100%, Play, Stop, and so on), and keep track of customized items. • ContextMenuItem. Each item in a context menu is an instance of this class. The ContextMenu class has a property (array) called customItems. Each element in that array is an instance of the ContextMenuItem class.The ContextMenu class and the ContextMenuItem class are used together to build customcontext menus.When creating a new instance of the ContextMenu class, you can specify a function to becalled when that ContextMenu is displayed:var myContextMenu:ContextMenu = new ContextMenu(menuHandler);The menuHandler() function is executed just before the context menu appears. Scriptwithin the function can be used to evaluate certain conditions within the application anditems on a context menu can be dynamically added, removed, enabled, or disabled. Forexample, a Save item may be disabled if nothing has changed since the last time the usersaved.You can dynamically change the function a context menu calls before it appears, byredefining its onSelect event handler. For example:myContextMenu.onSelect = anotherFunction;As a result of this script, the onSelect event handler is reassigned from its initial value tothat of anotherFunction. The myContextMenu instance will call anotherFunction()instead of menuHandler()—or whatever function you passed into the ContextMenuconstructor when creating it—when the context menu is selected (but before it appears).When creating custom context menus, you may want to remove the default items thatappear. To hide the built-in items in a context menu, you call the hideBuiltInItems()method:myContextMenu.hideBuiltInItems();With this method, all built-in items are hidden from the context menu except the Settingsand Debugger items.NOTEIn editable text fields, standard items such as Cut, Copy, Paste, Delete, and Select All arenot removable.Instances of the ContextMenu class have only one property—customItems. This is anarray that stores the custom ContextMenuItem objects that form the custom items thatappear on the menu. To add a custom item to a ContextMenu object, you add it to thecustomItems array for that object:myContextMenu.customItems.push(new ContextMenuItem(Next Page,nextPageHandler));This statement adds a new ContextMenuItem object to the customItems array of themyContextMenu object. The first parameter is the text to be displayed in the menu. Thesecond parameter is the callback function for that item. When the item is selected fromthe context menu, the callback function is called.Custom menu items in a context menu can be referenced in the following manner:myContextMenu.customItems[0] // first custom menu itemmyContextMenu.customItems[1] // second custom menu itemmyContextMenu.customItems[2] // third custom menu itemKnowing this, you can enable and disable menu items dynamically:myContextMenu.customItems[1].enabled = false;myContextMenu.customItems[3].enabled = false;Disabled menu items still appear on the custom context menu, but theyre dimmed andwont function when clicked. Menu items are enabled by default.You can dynamically change the function that a context menu item calls when selected,by redefining its onSelect event handler. For example:myContextMenu.customItems[0].onSelect = differentCallbackFunction;NOTEJust to clarify, the context menu itself has a callback function that is executed just beforethe menu appears, and each context menu item has a callback function thats executedwhen that item is selected from the menu.To use a custom context menu, it has to be assigned to a particular movie clip, button, ortext field instance. The assignment causes that custom menu to appear when the instanceis right-clicked. Heres the syntax:myClip_mc.menu = myContextMenu;When the mouse is right-clicked over the myClip_mc movie clip instance, themyContextMenu context menu is displayed.NOTEA single custom context menu can be associated with as many movie clip, button, andtext field instances as you want.When using custom context menus, the timeline with the highest depth always capturesthe right-click mouse event, which causes its custom menu to be displayed. For example,if two movie clips are overlapping and each has an associated custom context menu, theclip thats at a higher depth is the one whose menu is shown when the mouse is right-clicked over that clip. This principle also applies to the main timeline. If the mouse is notover a movie clip that has a custom menu, but the main timeline (_root) has a custommenu, the custom menu for _root will be displayed.In the following exercise, youll create a custom context menu with one custom item,used to print the contents of an editable text field. 1. Open ContextMenu1.fla in the Lesson21/Assets folder. ...
Nội dung trích xuất từ tài liệu:
Creating Custom Context Menus < Day Day Up >Creating Custom Context MenusThe context menu appears when you right-click a Flash movie (Control-click on aMacintosh). There are three different types of Flash context menus: • Standard menu. Appears when you right-click anything in a Flash movie except a text field. • Edit menu. Appears when you right-click a text field thats editable or selectable. • Error menu. Appears when a Flash movie fails to load within a Web page and you right-click in the empty area.The error menu cannot be changed, but the standard and edit context menus can becustomized to display new items or remove the built-in default items. All the built-incontext menu items can be removed except for the Settings item and the Debugger item.The Flash player includes two built-in classes to assist you in creating a customizedcontext menu: • ContextMenu. This class allows you to create a new context menu, hide built-in menu items (Zoom In, Zoom Out, 100%, Play, Stop, and so on), and keep track of customized items. • ContextMenuItem. Each item in a context menu is an instance of this class. The ContextMenu class has a property (array) called customItems. Each element in that array is an instance of the ContextMenuItem class.The ContextMenu class and the ContextMenuItem class are used together to build customcontext menus.When creating a new instance of the ContextMenu class, you can specify a function to becalled when that ContextMenu is displayed:var myContextMenu:ContextMenu = new ContextMenu(menuHandler);The menuHandler() function is executed just before the context menu appears. Scriptwithin the function can be used to evaluate certain conditions within the application anditems on a context menu can be dynamically added, removed, enabled, or disabled. Forexample, a Save item may be disabled if nothing has changed since the last time the usersaved.You can dynamically change the function a context menu calls before it appears, byredefining its onSelect event handler. For example:myContextMenu.onSelect = anotherFunction;As a result of this script, the onSelect event handler is reassigned from its initial value tothat of anotherFunction. The myContextMenu instance will call anotherFunction()instead of menuHandler()—or whatever function you passed into the ContextMenuconstructor when creating it—when the context menu is selected (but before it appears).When creating custom context menus, you may want to remove the default items thatappear. To hide the built-in items in a context menu, you call the hideBuiltInItems()method:myContextMenu.hideBuiltInItems();With this method, all built-in items are hidden from the context menu except the Settingsand Debugger items.NOTEIn editable text fields, standard items such as Cut, Copy, Paste, Delete, and Select All arenot removable.Instances of the ContextMenu class have only one property—customItems. This is anarray that stores the custom ContextMenuItem objects that form the custom items thatappear on the menu. To add a custom item to a ContextMenu object, you add it to thecustomItems array for that object:myContextMenu.customItems.push(new ContextMenuItem(Next Page,nextPageHandler));This statement adds a new ContextMenuItem object to the customItems array of themyContextMenu object. The first parameter is the text to be displayed in the menu. Thesecond parameter is the callback function for that item. When the item is selected fromthe context menu, the callback function is called.Custom menu items in a context menu can be referenced in the following manner:myContextMenu.customItems[0] // first custom menu itemmyContextMenu.customItems[1] // second custom menu itemmyContextMenu.customItems[2] // third custom menu itemKnowing this, you can enable and disable menu items dynamically:myContextMenu.customItems[1].enabled = false;myContextMenu.customItems[3].enabled = false;Disabled menu items still appear on the custom context menu, but theyre dimmed andwont function when clicked. Menu items are enabled by default.You can dynamically change the function that a context menu item calls when selected,by redefining its onSelect event handler. For example:myContextMenu.customItems[0].onSelect = differentCallbackFunction;NOTEJust to clarify, the context menu itself has a callback function that is executed just beforethe menu appears, and each context menu item has a callback function thats executedwhen that item is selected from the menu.To use a custom context menu, it has to be assigned to a particular movie clip, button, ortext field instance. The assignment causes that custom menu to appear when the instanceis right-clicked. Heres the syntax:myClip_mc.menu = myContextMenu;When the mouse is right-clicked over the myClip_mc movie clip instance, themyContextMenu context menu is displayed.NOTEA single custom context menu can be associated with as many movie clip, button, andtext field instances as you want.When using custom context menus, the timeline with the highest depth always capturesthe right-click mouse event, which causes its custom menu to be displayed. For example,if two movie clips are overlapping and each has an associated custom context menu, theclip thats at a higher depth is the one whose menu is shown when the mouse is right-clicked over that clip. This principle also applies to the main timeline. If the mouse is notover a movie clip that has a custom menu, but the main timeline (_root) has a custommenu, the custom menu for _root will be displayed.In the following exercise, youll create a custom context menu with one custom item,used to print the contents of an editable text field. 1. Open ContextMenu1.fla in the Lesson21/Assets folder. ...
Tìm kiếm theo từ khóa liên quan:
máy tính mạng máy tính internet phần mềm ứng dụng lập trình SQL HTML sever web XMLTài liệu liên quan:
-
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 279 0 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 259 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 257 1 0 -
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 257 0 0 -
47 trang 242 3 0
-
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 240 0 0 -
80 trang 229 0 0
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 1
122 trang 218 0 0 -
122 trang 217 0 0
-
Giáo trình môn học/mô đun: Mạng máy tính (Ngành/nghề: Quản trị mạng máy tính) - Phần 1
68 trang 214 0 0