bbb Home |
Lesson 5 - Open the Game Window |
SUMMARYIn this lesson you will modify the home page for your game by making the "Start Game" <div> behave as a button to open the game window. DISCUSSIONJavaScript is an object-oriented language. An object is a "container" or "programming construct" that can hold data (properties), perform actions (methods), and respond to events . We have already learned about events. One object in JavaScript is the Window object. This object has a number of methods. A method is like a verb; it is in an action that the object can do. One such method is open . The open method will open a new window. Methods accept parameters. A parameter is information that the method needs to perform its action. For example, before opening a new window, the open method needs to know information such as what web page to put in the window and how big the window should be. The open method is flexible and can accept just a few parameters or many parameters. The format for the open method and the parameters are listed below: winName = window.open("url", "name", "features")
As will be demonstrated in the examples, the parameters are optional. Line 4 demonstrates the most simple use of the open method. When the <div> is clicked, a new window is opened. Since no url is passed into the method, the window opens with nothing in it. In line 5 a filename is passed into the open method so that the web page example5.htm is displayed in the window. The file example5.htm is in the same folder as this page. In lines 6 and 7 a window called winX is opened and the document.write method is used to write the word "hi" to it. Notice that the onclick event for the <div> in Lines 6 and 7 does two things. First it opens the window and then it writes to it. When events do more than one action, the actions are separated by a semicolon. In line 8 the window opened in line 6 is closed when the user clicks on the <div>. In lines 9 to 11 a window is opened and a page from a site is displayed. Some of the window features such as width, height, left, and top are specified. Notice how they are separated by commas. EXAMPLE - Opening Windows
PRACTICE
GAME DEVELOPMENT
|
References |
©dfx interactive, inc. Contact us at bigbadbrain@bigbadbrain.com |