Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Covering diverse topics such as improving workflow and managing CSS styles, Dreamweaver CS3 Beyond the Basics is a hands-on course that teaches users how to move beyond standard, static websites. Instructor James Williamson explores how to increase productivity, interactivity, and accessibility with Dreamweaver. He also discusses how to extend the application's capabilities with XML and XSL. Exercise files accompany the tutorials.
Okay, so what does this function do? Well, what this function is going to do for us is if somebody is using your Behavior and they have a link highlighted and they go up to the Behaviors panel and say plus and then chooses Behavior, this function is going to take care of which script is called In Run and what events are added to the link that they had highlighted. So we will go down to the next line, and I am going to type in, function applyBehavior, and I am going to open and close a parentheses. I will open up a Curly Brace, and as a habit, I am going to hit Enter twice and close our curly brace. Again, that always ensures that we have a both an opening and a close.
So we are saying Documents, we go into Current document and then we are saying theForm. So find an element named theForm and if you remember, that is what we named the form in our Actions file in the previous exercise. Then we're saying, find an element called Title. That would be the text field that the user is going to type into. And then finally, we are saying, we want you to retrieve the value from that. So it's going to pull whatever value is currently inside of that text field. So we will go down to the next line and type in return and then in quotation marks, setActiveStyleSheet and really be careful of your capitalization and your spelling there. Open up a parentheses and then close your quotation marks, and type a plus symbol and type in theName, another plus symbol, open up a quotation mark, close the parentheses, close your quotations, and type in a semicolon.
But the name on the other hand is a variable and it needs to be evaluated, what is the value of the name. That value is going to be equal to whatever has been entered into the form. So essentially, what we are doing is we are doing the setActiveStyleSheet function call, but we are adding to it the value of whatever has been typed into the interface. So now, we can go down to our final core function and our final core function is going to allow people to modify our behavior once they have applied it. For all, in terms of purposes, our behaviors are now finished. But it wouldn't really be of that kind of a behavior if somebody couldn't edit it.
What happens if they type in a wrong style sheet name or they decide that they want to change the style sheet later on? Well, if you didn't add this next function, they wouldn't be able to do that. So I am going to go ahead and type in a single line comment, and I will enter in, Allows user to modify the behavior after initially applying it. So you don't have to be that robust with your commenting, you just want to identify exactly what this function is doing in a nice, succinct manner. We will go ahead and define another function. So type in function, and after that, I am going to type in, inspectBehavior.
Now, our other core functions weren't really expecting any arguments to be passed into them, but this one does. And the argument that this one is going to be looking for is enteredStr, entered String. So I will close my parentheses, open up a curly brace, hit Enter twice again, close the curly brace. All right, so now we are ready to go ahead and enter the code for the inspectBehavior function. Now, it's expecting one value to be passed in and that value is Entered String. So the first thing I am going to do is just go ahead and declare a variable inside this function, and I am going to type in var argArray.
I am going to go down to the next line and I will type in another single line comment here and we will type in, this will retrieve the string entered by the user. So we know what our next line of code is about is about to do. So on the next line of code, type in var argArray. But we are going to go ahead and assign a value to it now. So equals, extract args, plural, and then open up a parenthesis and type in enteredString. That's the value being passed in through the function.
So go ahead and type in another semicolon. Then we will do another single line comment inside the function and type in use an array value of 1, since the first item returned is the name of the function called. And unfortunately, sometimes you have to be for both when you're doing your comment. All right, now we will type in document. theForm.title.value equals argArray and then in bracket notation, not parentheses but bracket notation, type in the number 1, type in the end of your bracket and type in a semicolon. Now be sure to save your file.
What the extractArgs function does is it peruses your entire document and it will find any string values that had been entered into this particular form. So anything has been entered into this form will be returned as an array. Now as the array returns, the first item in array and that would be zero, if we remember, the first time in the array which we numbered zero, will be the name of the function that's called. After that, will be a list of strings that were passed into the function. We are only interested in the first one, which would be whatever value somebody typed in. So since the first item is actually going to be the name of the function call, we need to pass in one, which in reality is the second item. That seems confusing, until you are used to using arrays, because you always know the first number is zero and then after that, it's one, two, three, four, five.
So our behavior is pretty much finished. In our next exercise, we will add a nice little bit of usability to our form by establishing focus on the form element when the dialog box originally opens.
Find answers to the most frequently asked questions about Dreamweaver CS3 Beyond the Basics.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.