Search

Using Flash and Java to create Pop-Ups

0 views

Designing the Flash Button to Trigger a Pop‑Up

When working with Flash, one of the most common tasks is to give the user a way to access additional information or functionality without leaving the current scene. A pop‑up window is a simple and effective solution, and by combining a small Flash button with a bit of JavaScript you can open a customized window that contains anything from a form to an advertisement.

Below is a step‑by‑step walk‑through that keeps the design as clean as possible. The goal is to show how the Flash side of things can be wired to JavaScript so that clicking a button inside a movie triggers the pop‑up.

First, open Adobe Flash (or Adobe Animate) and start a new FLA file. The canvas size can be whatever fits your project; for the purpose of this tutorial a 300 × 150 pixel stage is sufficient. Use the Rectangle tool to draw a rectangle that will become the button. Give it a distinct fill color so it stands out.

Next, select the rectangle with the Selection tool, then press F8 (or right‑click and choose Convert to Symbol). In the dialog that appears, choose “Button” as the type, name it “popupButton”, and click OK. The new button symbol appears in the Library panel. Double‑click the button symbol to open its timeline.

In the button timeline you will see three frames: Up, Over, and Down. They represent the visual state of the button. For a basic demo you can leave the frames unchanged, but feel free to add a different color or label in the Over state to provide visual feedback.

Now it’s time to attach the ActionScript that will fire when the button is released. Right‑click on the first frame of the button timeline, choose Actions, and a new panel opens on the right. In the code editor paste the following snippet:

Prompt
on (release) {</p> <p> getURL("JavaScript:openPopup();");</p> <p>}</p>

This small piece of ActionScript uses the legacy on event handler. In older versions of Flash it is still supported and keeps the code short. The getURL call passes a command to the browser: it asks the host page to run the JavaScript function openPopup(). The string inside the parentheses tells the browser to execute the JavaScript code that follows the colon.

After entering the code, save the FLA file. To test the movie, choose File → Publish, then click the Flash panel’s Play button. When the button in the movie appears, clicking it will trigger the getURL call. Since the page currently contains no JavaScript function named openPopup, nothing will happen. This is expected; the next step is to add the JavaScript function to the host HTML page.

Before moving on, a quick reminder: Flash is no longer supported by most modern browsers. The techniques shown here are relevant mainly for legacy projects that still run in environments where Flash is enabled. If you’re looking to implement similar functionality in a contemporary web application, consider using HTML5, CSS, and vanilla JavaScript instead.

John, the creator behind FlashTools, has written extensively about maintaining Flash applications. In his tutorials he explains how to integrate Flash with server‑side scripts and how to manage memory usage when deploying complex interactive projects. Drawing from his experience, the button‑to‑popup pattern is one of the few that still offers a clean separation between the Flash movie and the surrounding web page.

With the button now wired to a JavaScript call, the only thing left is to write that function. Below, you’ll find a straightforward JavaScript implementation that opens a new browser window with custom settings. The code is designed to work on most browsers that support the window.open API. Feel free to adjust the size, position, and features of the pop‑up to match your design.

Adding the JavaScript Popup Code to Your Web Page

To complete the pop‑up chain, the host HTML file must contain a function named openPopup(). Place the following script inside the <head> section of the page that hosts your Flash movie:

Prompt
<script language="JavaScript"></p> <p>function openPopup() {</p> <p> window.open(</p> <p> 'https://www.flashtools.com/help.html',</p> <p> '',</p> <p> 'toolbar=no,location=no,status=no,menubar=no,'</p> <p> +'scrollbars=yes,resizable=yes,width=600,height=400,'</p> <p> +'left=100,top=100'</p> <p> );</p> <p>}</p> <p></script></p>

The window.open function takes three arguments: the URL to load, a window name (empty string is fine if you don’t need to refer to the window later), and a comma‑separated string of window features. In the example above the pop‑up is 600 × 400 pixels, resizable, and has scrollbars if the content overflows. You can modify the URL to point to any page you want the user to see, such as a contact form, a product showcase, or a custom Flash movie itself.

Once the script is in place, reload the page in a browser that still supports Flash. Click the button inside the Flash movie. The browser will execute the openPopup() function, and a new window should appear. If you’re running the page locally, most browsers will block pop‑ups by default; in that case, you’ll need to adjust the browser’s pop‑up settings or test in a trusted environment.

It’s worth noting that many modern browsers block window.open calls that are not directly triggered by a user event. In our scenario the click on the Flash button counts as a user event, so the pop‑up should succeed. However, if you encounter issues, double‑check the JavaScript console for errors and verify that the openPopup() function is defined correctly.

For projects that need to support multiple browsers or devices, consider adding a fallback. For example, you can have the JavaScript open a modal overlay within the same page instead of a separate window. That approach uses pure HTML and CSS for the overlay, while the Flash button remains responsible for triggering the JavaScript call.

In conclusion, this method demonstrates how a simple Flash button can communicate with the hosting page’s JavaScript to launch a customized pop‑up. The key steps are: create a button symbol, attach an on release handler that calls getURL("JavaScript:openPopup();"), and implement the openPopup() function in the page’s <head> section. Even though Flash is no longer mainstream, understanding these interactions can help maintain or migrate legacy content that still relies on this pattern.

Suggest a Correction

Found an error or have a suggestion? Let us know and we'll review it.

Share this article

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!

Related Articles