Simple Hyperlinks

 < Day Day Up > 

This hour you've seen how to publish your movies to a browser. But what good is a Flash movie in a browser if it doesn't do "web stuff"? There's nothing wrong with making a Flash movie that simply entertains. But if your users are already on the Web, you might as well give them a way to hyperlink to other web pages.

There's only one script you really have to learn to create a hyperlink: getURL (also called Go to web Page found under the web category when you press the plus button in the Behaviors panel). (If you already know how to create a hyperlink in HTML, you can think of this action as the same as a href.) Specifically, when Flash encounters the getURL action, it takes the user to a new web page, either within your site or to another website altogether. That's the simple explanation. Naturally, there are more details. You'll use this action to see how it works in the following task.

Try It Yourself: Use getURL to Create a Hyperlink

In this task you'll create a button that, when clicked, takes the user to another website. Here are the steps to follow:

1.

Create a new file and save it in an empty folder. (This step isn't absolutely necessary, but it is useful when you're creating complex websites because all the files and folders can get out of hand; therefore, I like to start with a nice clean folder.)

2.

Drag a Button component onto the Stage and use the Properties panel to change its Label parameter to Go.

3.

Attach a behavior to the button by selecting the instance of the button on the Stage, opening the Behaviors panel, and finding Go to web Page. Just press the plus button and find it under web.

4.

When the dialog box appears, you need to indicate the web address to which you want the user to navigate. In the URL field, type http://www.samspublishing.com, as shown in Figure 19.3. You'll learn about the other parameters later, so leave them alone for now.

Figure 19.3. The Go to Web Page behavior requires that you specify the address to which you want the user to navigate.


5.

Select File, Test Movie. When you click, you are taken to the Sams Publishing website.

6.

Next try File, Publish Preview, Default (or press F12). This time the Flash movie plays in a browser, and when you click the button you'll probably see the new extra-secure warning dialog added in Flash Player 8. The issue is that a file on your hard drive (after all you haven't uploaded this movie yet) can be either local files or files on the internet, but not both. You can click the Settings button and then explicitly authorize this file. Click the Edit Locations drop-down and select Add Location then click Browse for folder and select the folder you created in step 1. Next time you select Publish Preview it should work.

By the Way: Flash 8 Security

The new security change that can make the tasks in this hour difficult to test have to do with the new rule that a .swf running on your desktop (that is, not on a web server) may only access other files on your desktop (but not the Internet). You can change the Local playback security setting (in the Flash tab of the Publish Settings) to "Access network only" and the .swf will only be able to access the Web. The first point to understand is your .swf (running locally) can access the Web or local file but not both. I'm not going to suggest changing the local-only default because while that will let you test the Go to web page behavior (getURL()) locally it will disable other features such as loading locally stored images runtime (as you'll do next hour). Remember that once you upload your .swf (even with the local-only setting) it will be able to load external images and jump to other web pages.

You may think that because you only plan on delivering files to the Web all this is unimportant. However, in order to test without uploading the files (which would be a big pain, say, every time you did a test movie) you need to configure your computer for testing. It's pretty easy. First, realize none of this applies when you do a test movie because Flash's security measures don't apply (although you may see an informational message in the output window though everything still works). For testing locally in the browser (and for the rest of this chapter) you should set up a .cfg file that defines a folder on your computer where the Flash Player knows the content is trusted by you (thereby disabling the security restrictions for just that folder). (In fact, that dialog you saw in the previous task only appeared because of a file called FlashAuthor.cfg that effectively says "show warnings because I'm authoring" end users shouldn't see that dialog.)

Anyway, you can specify individual .swfs or an entire folder where it's okay for files to access both the internet and local files. So, pick a folder for projects in this book: for example, I'll use C:\Documents and Settings\Phillip\My Documents\STY Book\

Next, you need to find the Flash Security folder. On Windows it will be in:

c:\Documents and Settings\<user name>\Application Data\Macromedia \Flash Player\#Security

Mac:

/Users/<username>/Library/Preferences/Macromedia/Flash Player /#Security

Create a folder inside the #Security folder named FlashPlayerTrust. Finally, make a text file and name it with the .cfg extension. For example: book.cfg. Inside this text file type the path to the folder you're okaying. For example:

C:\Documents and Settings\Phillip\My Documents\STY Book\

You can add as many locations as you want (and, in fact, add as many files as you want to that FlashPlayerTrust folder).

That's it. Now you can simply save all your projects while testing in that folder and they'll behave as the will when posted on a real web server.


Now that we have the security issue out of the way, let's look at two other ways (in addition to using getURL) you can create hyperlinks inside Flash, and they both involve using text. Any static text can have a URL associated with it automatically. You'll learn about this method in the following task.

Try It Yourself: Create a Text Hyperlink

In this task you'll use an automatic feature to associate a hyperlink with a block of text. Here are the steps:

1.

Create a block of text using any font you like just make it big enough to read.

2.

With the text block selected, access the Properties panel. First make sure the text type is Static (not Dynamic or Input), and then type a legitimate URL into the URL Link field (next to the chain-link icon). In Figure 19.4, http://www.phillipkerman.com is used. The text becomes hyperlinked text, also called hypertext.

Figure 19.4. You can make a selected block of text a hyperlink by specifying a URL link in the Properties panel.


3.

Select Publish Preview. I like this method because it doesn't involve any behaviors; it's just a built-in text property. Notice that the new page replaces the browser window. As you'll see in the "Targeting Windows" section later this hour, it's possible to change the target window to blank to see the linked page appear in a new window instead.

Now you'll learn the third way you can create hyperlinks: using dynamic text. This method, like the previous one, applies only to text. Dynamic text also has an option for HTML that allows you to populate a text block (through setting the associated variable) with actual HTML code. You'll see how this is done in the following task.

Try It Yourself: Use Dynamic Text to Create a Hyperlink

In this task you'll create HTML within a Flash text block. Follow these steps:

1.

Use the Text tool to create a long block of text. It doesn't matter what you type because the text will be replaced.

2.

With the text block selected, use the Properties panel to set the text type as Dynamic and give this instance the name my_txt. Also, make sure you have Render as HTML selected and Selectable unselected (see Figure 19.5). (You can effectively click the Render as HTML option using the script: my_text.html=true)

Figure 19.5. Selecting dynamic text and the HTML option for the text block allows you to create HTML in Flash.


3.

In the first keyframe, populate the my_txt instance by selecting the first frame and accessing the Actions panel. Then type the following code:

 my_txt.htmlText="This is <A HREF='http://www.yahoo.com'>Hot</A>." 

4.

(Note that you set the htmlText property, not the text property as you do when populating with plain text.) If you understand the HTML, great. Otherwise, just accept it for now. It will make sense later. Select Publish Preview.

By the Way: Quotes Within Quotes

Notice the single quote marks for the nested string around the web address. If you need to include regular quote marks within a string (which always begins and ends with quote marks), you have to "escape" the nested quote. In other words, my_txt.text="I said "No"" won't work because Flash will think the quotation mark right before No is the ending quotation mark for the string started before I. To make it work, precede the literal quote mark with a backslash character (\), like this: my_txt.text="I said \"No\"". Using single quotes when possible is much easier.


     < Day Day Up > 


    Sams Teach Yourself Macromedia Flash 8 in 24 Hours
    Sams Teach Yourself Macromedia Flash 8 in 24 Hours
    ISBN: 0672327546
    EAN: 2147483647
    Year: 2006
    Pages: 235

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net