`
天梯梦
  • 浏览: 13730808 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

Popup window ActionScript3 VS ActionScript2

阅读更多

A common feature that you can see on many Flash sites is the pop-up window. While this site features several tutorials on creating variations of the pop-up window, this one is a little bit different; it is centered. You click a button and the new window opens in the center of your screen regardless of your resolution.



Displaying a Centered Pop-Up Window:

  1. Create a new movie by going to File | New. Set the width and height of your movie to anything you choose.
     
  2. Draw a circle that will act as your button. Once you have drawn your circle, select it and press F8 (Insert | Convert to Symbol). The Convert to Symbol dialog box will appear. Select Button and press OK.

[ select "Button" and press OK]

  1. Now that the circle is a button, it is time to add some actions. Right click on the button and select Actions. The Actions dialog box will appear. Copy and paste the following code:
 on (release) {

    //customize the window that gets opened
    // 0 equals NO.
    // 1 equals YES.
    address = "http://www.kirupa.com/modular/pop-up.htm";
    target_winName = "kirupa";
    width = 400;
    height = 300;
    toolbar = 0;
    location = 0;
    directories = 0;
    status = 0;
    menubar = 0;
    scrollbars = 1;
    resizable = 0;
    //sends data back to the function
    openWinCentre(address, target_winName, width, height, toolbar, location, directories, status, menubar, scrollbars, resizable);

    }
   
  1. The last step involves adding some more actions. Insert another layer on your timeline and name it "actions".
     
    Right click on the keyframe on the "actions" layer and select Actions . Copy and paste the following code into the Actions dialog box that appears:

 

 _root.openWinCentre = function (url, winName, w, h, toolbar, location, directories, status, menubar, scrollbars, resizable) {

    getURL ("javascript:var myWin; if(!myWin || myWin.closed){myWin = window.open('" + url + "','" + winName + "','" + "width=" + w + ",height=" + h + ",toolbar=" + toolbar + ",location=" + location + ",directories=" + directories + ",status=" + status + ",menubar=" + menubar + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",top='+((screen.height/2)-(" + h/2 + "))+',left='+((screen.width/2)-(" + w/2 + "))+'" + "')}else{myWin.focus();};void(0);");

    }					
 
  1. Save the animation and preview it in your browser. You will notice that the window appears perfectly centered.

Customizing the Window
Unless you want your pop-up window to display updates from the kirupa.com site, you probably want to modify the window size, content it loads, and the window's attributes such as toolbars, etc. The following information should help you to customize the window.

Right click on your button and select Actions. You will see in the first few lines, that I mentioned the property and its value. To change the URL of the page that gets opened, simply change the text in quotation marks after the word "address". To enable a property that is disabled like displaying the status bar, find the line that says "status =" and change the 0 to a 1. Simple as that. I will explain what each variable stands for in the real world:

  • address
    The address is the path to the page you want to have opened in the pop-up window.
  • target_winName
    This is the name of the window that will be opened. If you are familiar with frames, you will know that each frame-page has a name attached to it. When you link, you specify the name of that frame to load a page into.

    This tag works very similar for the pop-up window. If you want anything to be loaded into the window, you would target the window name you specify. You don't have to worry about this tag unless you are familiar with HTML. Just enter a word and move on!
  • width
    Here is where you would specify the width of the window that appears.
  • height
    Here is where you would specify the height of the window that appears.
  • toolbar
    Specifies whether you want the pop-up window to display the browser's toolbar with the back/forward buttons.
  • location
    Specifies whether you want the address bar to be displayed in your browser.
  • directories
    Specifies whether you want other toolbars installed by the user in their browser such as a Google toolbar or a Links toolbar to displayed when a page is opened.
  • status
    Specifies whether you want the status bar toward the bottom of the window to be displayed.
  • menubar
    Specifies whether you want the menu bar with the File, Edit, View Tools, etc. commands to be visible near the top of the browser.
  • scrollbars
    Specifies whether you want the scrollbars to be displayed in the window. If the content exceeds the size of the window, I highly recommend you enable the use of scrollbars. If the content snugly fits within the window, you may disable the scrollbars feature if you would like!
  • resizable
    Specifies whether the use will be able to resize the window by dragging the edges of the window.
     

As always, I have provided the source code for you to compare your version with that of mine. Make sure you have WinZip installed on your computer.


download source for flash mx






Using Actionscript 2 all you need to use is this on your button….

on(release){
getURL (“javascript:popUp(‘http://www.cartoonsmart.com/fx_examples/the_gloom.html’)”);
}
 

…..WITH  the javascript below somewhere between your Head tags in the html thats embedding your swf….

<SCRIPT LANGUAGE=”JavaScript”>
function popUp(theURL) {
var top=open(theURL,”winname”,”width=600,height=500,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0″);
top.focus();
}
</SCRIPT>
 

Notice the function name popUp which appears in both sets of code. That should clue ya in as to how this works. And if you do want it to work, be sure you upload everything and test it live. Locally won’t do thing. You can see a working example here . Which is the same file included in the source files linked up below. 

 

Now using Actionscript 3, here’s some less-than-perfect code for a movieclip with an instance name of your_button

    var js:URLRequest=new URLRequest();
    js.url=”javascript:window.open(‘http://www.cartoonsmart.com’,'popUp’,'width=800,height=400′);newWindow.focus(); void(0);”;

    your_button.addEventListener(MouseEvent.CLICK,openPopUp);

    function openPopUp(evt:MouseEvent):void {
    navigateToURL(js,”_self” );
    trace( “Warning! this might not work in browsers that are set to block pop up windows”);
    } 

 

This example doesn’t need any javascript written in an html file. Come to think of it, I probably could have found a similar method in AS2 that didn’t require adding code to your html, but whatever, it works.  You can see an example of the AS3 Flash popup here … But remember, it probably won’t work if your browser prefs block popups.







分享到:
评论

相关推荐

    仿微信popup window

    3. **初始化popup window**:创建PopupWindow实例,传入加载好的View,设置其宽度、高度、是否可触摸等属性。 4. **设置动画**:为了达到微信那样的动画效果,需要自定义动画资源文件,例如渐显渐隐、滑动进出等。...

    popup window

    Popup Window在IT行业中是一个常见的术语,它主要指的是在用户界面中弹出的一个小型窗口,用于显示额外的信息或者进行特定操作。这种技术广泛应用于各种软件、网站和移动应用中,为用户提供交互式的体验。本篇文章将...

    bottom_popup_window

    在Android应用开发中,"bottom_popup_window"是一个常见的设计元素,用于展示临时的通知或功能选项。这个标题描述了一个简单易用的底部弹窗效果,它从屏幕底部滑入,用户可以通过点击外部区域轻松滑出,同时也支持...

    一个采用C#+ASP.NET实现的Modal popup window图片模式窗体展示程序代码

    【C#+ASP.NET Modal popup window 图片模式窗体展示程序详解】 在Web开发中,Modal Popup Window(模态弹出窗口)是一种常见的交互设计模式,它用于在用户操作当前页面时显示临时信息或进行交互。在ASP.NET环境中,...

    Change from child window to popup window (and back)(277KB)

    标题为“Change from child window to popup window (and back)”的主题涉及到Windows API中的两种主要窗口类型:子窗口(Child Window)和弹出窗口(Popup Window)。理解这两种窗口类型及其转换方法对于Windows...

    Popup Window-开源

    3. 遵守浏览器规范:确保Popup Window的实现符合W3C标准和浏览器的推荐做法,避免被浏览器视为恶意行为。 4. 测试与兼容性:在多种浏览器和设备上测试Popup Window的显示效果和功能,确保其在各种环境下都能正常...

    一个基于ASP.NET实现的Masked Div Or Modal Popup Window程序源码例子

    在本源码例子中,“基于ASP.NET实现的Masked Div Or Modal Popup Window”是一个功能,它允许在网页上创建遮罩层弹出窗口,通常用于显示警告、确认对话框或者加载内容时提供一种半透明的覆盖层,以防止用户在处理...

    dialog popup window

    在网页设计中,"dialog popup window"是一种常见的交互元素,用于向用户展示信息或获取用户的输入。这个压缩包提供了一套完整的解决方案,用于创建美观且功能丰富的弹出对话框。以下是对这些文件及其关联知识点的...

    Yc_ui_popup_window源码

    在Android开发中,`Yc_ui_popup_window`是一个常见的自定义弹窗库,它提供了丰富的弹窗样式和功能,使得开发者能够更加灵活地定制属于自己的弹窗组件。这个开源项目通常包含一系列源码文件,例如布局文件、Java或...

    popup 弹出框 js

    2. `window.confirm()`: 显示一个带有“确定”和“取消”两个按钮的确认对话框。用户的选择会返回一个布尔值,`true`表示“确定”,`false`表示“取消”,根据返回值可以执行不同的操作。 3. `window.prompt()`: ...

    Popup例子 实现弹出窗口的关闭

    2. **添加Popup内容**:在Popup的内部,可以添加任何你想要展示的UI元素,如TextBlock、Button、Image等。 3. **响应事件**:为了实现点击弹出窗口外部关闭Popup的功能,我们需要监听窗口的触摸事件。在后台代码中...

    Popup

    例如,使用`window.open()`函数可以创建一个新的浏览器窗口,或者通过CSS定位一个隐藏的元素使其可见来模拟弹出效果。 在应用程序开发中,Popup通常是对话框的形式,如消息框、选项框或输入框。这些组件通常由编程...

    关于popup的使用

    在JavaScript中,最简单的popup实现是使用`window.open()`函数创建新窗口。这个函数接受一个URL和一个窗口名称作为参数,可以用来打开一个新的浏览器窗口或标签页。例如: ```javascript var popup = window.open('...

    Popup_Window:这是一个简单的项目,用于展示如何在弹出窗口中打开 url

    3. **resize**:可能是指在JavaScript中调整弹出窗口的大小,可以通过`window.resizeTo()`或`window.innerWidth/innerHeight`属性来实现。 4. **browser**:指的是这个项目适用于多种浏览器环境,确保在不同的浏览器...

    actionScript3.0 API

    - popup.css 可能涉及弹出窗口或提示框的样式,比如代码示例或帮助信息的显示。 - content-ie6.css 专门针对Internet Explorer 6浏览器的兼容性问题,保证在较旧的浏览器上也能正常显示。 综上所述,ActionScript ...

    popup.js及详细示例

    3. **CSS样式控制**:为了改变弹出框的外观,`popup.js`可能会操作CSS属性,比如改变元素的可见性(`display`)、位置、大小等。这可以通过`element.style`对象来实现。 4. **弹出框的显示与隐藏**:`popup.js`中会...

    Popup-Closer:关闭所有以WindowType'popup'打开的窗口

    3. **遍历窗口对象**:Popup-Closer可能遍历`window.opener`、`window.parent`和`window.frames`属性,查找并关闭所有`WindowType`为'popup'的子窗口。 4. **窗口操作**:JavaScript提供了诸如`window.close`的方法...

    popup:通过 window.open() 创建原生弹出窗口的组件

    var popup = window.open(url, name, features); }); ``` 在上面的代码中,我们创建了一个名为`popupWindow`的新窗口,设置了它的大小、位置和其他特性。`popup`变量现在引用了新打开的窗口,你可以通过它与窗口...

    wpf使用Popup封装数据筛选框,wpf使用Popup封装数据筛选框

    在Windows Presentation Foundation (WPF) 中,`Popup`...通过打开`WpfApp3.sln`,我们可以查看并学习这个例子的具体实现方式,包括如何使用`Popup`来封装数据筛选框。如果遇到问题,可以联系博主以获取支持和帮助。

Global site tag (gtag.js) - Google Analytics