Archive for August, 2009

Q&A

Can I use getURL to open HTML pages on the user’s local hard drive?

A1: Yes, just like you could by using an tag in HTML. The getURL command just passes the information along to the browser. The browser does all the work. So anything a browser can do with a URL, the getURL command can do.

Q2: Can two Flash movies on one HTML page communicate with each other?

A2: If the browser supports JavaScript communication, you can write code to use JavaScript to pass messages between movies.

Q3: Is there any way at all to allow browsers that don’t have JavaScript communication capability to open windows with custom options?

A3: Yes. You could use Flash to open a window with getURL and then have some JavaScript code on that page to have it resize itself and change its options

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Summary

Using the getURL command, you can load a new Web page to replace the current one, or load a new Web page in another frame or window. You can use the special parameter _blank to load a new page in a new window.

ActionScript has the capability to communicate with JavaScript, provided that the browser supports this communication. You can use fscommand to send messages to the HTML page where a special JavaScript function intercepts it. From there, you have to write JavaScript code that uses the information sent.

You can also have JavaScript send information back to Flash. A whole set of commands can be sent to Flash, including ones that change frames and set variables.

The fscommand can also perform special tasks in projectors, such as quitting the projector, enlarging the projector to full screen size, or running another application.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Special Projector Commands

The fscommand command can also be used in projectors, which are standalone Flash movies. However, only a few special commands can be used.

The simplest command is quit. This takes no second parameter but simply exits the projector quickly. Here is a script for a projector quit button:

Two commands deal with scaling. The fullscreen command takes a true or false as a value and forces the projector to scale up to the full size of the user’s screen. The allowscale command, if set to true, scales the movie to fit whatever size the projector window is currently.

The showmenu command turns on or off the menus that the user sees with the projector.

Finally, the exec command takes a given path and attempts to execute an application at that path. This could be another projector or something like Wordpad.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Also add an swLiveConnect=true to the EMBED tag.

Also add an swLiveConnect=true to the EMBED tag.

Add two buttons to the HTML page. Use this code:




These two buttons call one of two functions. They both use TcurrentFrame(”/”) to get the number of the current frame and then GotoFrame to go to either the next or previous frame in the movie.

Test your movie or use the files in the 17slideshow folder. The handy thing about this technique is that you can easily substitute any Flash movie and it instantly makes a slideshow presentation out of it. You’ll either need to put a stop() at the start of the movie or add a play=false parameter in the tags so that the movie does not advance past the first frame when it starts.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Task: JavaScript-Controlled Slideshow

Here’s a task that can be performed easily with JavaScript, provided that the user has the right browser. In this task, we’ll build a movie that doesn’t have much of any ActionScript in it at all. The JavaScript on the HTML page, however, controls it completely.

Create a new Flash movie with three or more different frames in it. It doesn’t matter what is on each frame, as long as you can easily tell the difference between frames.

Place a stop() command on the first frame so that the movie doesn’t animate.

Publish the movie with a standard HTML page. There is no need to use the Flash with FSCommand template.

Using a text editor, open the HTML page.

Add an ID parameter to the OBJECT tag and a NAME parameter to the EMBED tag. Use “slideshow” as the value for both.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

To run the initComm function

To run the initComm function at the right time, you need to edit the BODY tag of the HTML page:

This runs the function only after the HTML page is finished loading. If you run it any earlier, the Flash movie may not be there to get the message.

Now, go back to your button script. Change it to call either fscommand or getURL depending on the value of jsCommOK.

The folder 17newwindow contains all the files used to make up this example. In addition, the Flash movie has a dynamic text field linked to the variable jsCommOK. You should see this variable change values as the initComm function sends its message.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Create a simple HTML page named content.html.

Create a simple HTML page named content.html.

If you open the HTML page in a browser capable of supporting JavaScript communication, you should be able to click on the button and get the window to appear. It should be 320´240 without a toolbar.

But what about browsers that don’t support JavaScript communication? Well, we can use a getURL command to open a standard new window in them. However, the trick is knowing which command to execute in which situation.

Back in the HTML page, add the following JavaScript function to the end of the JavaScript inserted by Flash’s Publish command:

This function tries to set the variable jsCommOK in the Flash movie to the string “OK”. If the browser is capable of JavaScript communication, the command should be successful. If not, jsCommOK will remain undefined.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Task: Open a New Window

Perhaps the most common task that Flash developers demand from browser communication is the ability to open a new browser window. This is something that can be done with both the getURL command and JavaScript communication.

However, JavaScript has one distinct advantage: You can specify the size and properties of the new window. Here’s how to do that:

Create a new Flash movie.

Place a button in the movie.

Attach this script to the button:

In the Publish settings, choose to export an HTML page as well as a Flash movie. In the HTML page, choose Flash with FSCommand as your template.

Publish the movie.

Open the HTML page in a text editor. Look for the portion of the JavaScript function where you can place your own commands. Insert this in that spot:

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

You can use GetVariable

You can use GetVariable and SetVariable to look at and control variables on the main timeline. The Zoom command allows you to control the scale of the movie. The isPlaying and percentLoaded functions allow you to detect what the movie is doing at the time. The simple Play command moves the movie forward from its stopped state.

You can also use TgotoLabel to use a frame name rather than a number. The TGetProperty and TSetProperty commands seem simple enough, except that they can’t refer to a property by its real name. Instead, they have to use a number to refer to each property. So _x is 0, _y is 1, _visible is 7, and so on.

To find out more about JavaScript communication, you’ll have to go to the Macromedia Web site. The documentation has only a small amount of information and does not list the commands or the property numbers. Perhaps this is because of the doesn’t-work-on-every-browser issue.

To get to the special section about this topic, go to http://www.macromedia.com/support/flash/ and search on Flash Methods. You’ll eventually find the document that contains a lot of information about this subject.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Getting Messages from JavaScript

Sending messages from the HTML page to your Flash movie is easier than the other way around. First, you need to make sure that you set an ID parameter for the OBJECT tag and a NAME parameter for the EMBED tag. Make them the same value. You will also need to set swLiveConnect to true in the EMBED tag.

Now you have a host of commands that you can send to the Flash movie. For instance, you can use GotoFrame to tell the movie to go to a specific frame number. Here is a button that tells the movie flashmovie to go to frame 2.

If this code is supposed to make the movie go to frame 2, why is there a 1 in the GotoFrame command? This is another case where the numbering is zero-based. So frame 1 is 0, frame 2 is 1, and so on.

There are 24 more commands that you can use on a Flash movie. However, I don’t want to spend too much time on this because, as I mentioned at the start of this section, JavaScript communication doesn’t work on all browsers, so it is not considered by most developers to be of any use.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

  • Partner links