Muchos de nosotros, aveces, nos vemos obligados de abrir un popup desde Flash y para eso utilizamos ExternalInterface que ya vimos en un tutorial aquí en Cristalab. Sin embargo, para algunas personas no familiarizadas con el código, se les hace un mundo cuando comparan esa forma con el clásico método getURL de ActionScript 2.0. De hecho zguillez hizo un tip en AS2.
Para eso hice una pequeña clase que nos ayudará a resolver este dilema utilizando navigateToURL, pero déjenme insistir en utilizar ExternalInterface.
Para eso creo mis variables por default, donde declaro la url a abrir, el ancho y alto, el título de la ventana, si será resize y en que ventana abrirá
Código :
private var _url:String = "http://www.cristalab.com"; private var _width:Number= 400; private var _height:Number= 300; private var _title:String = "title"; private var _resize:String = "yes"; private var _window:String = "_blank";
Código :
public function openWindow(newUrl:String = null):void{
if(newUrl)
this.url = newUrl;
var _urlRequest:URLRequest=new URLRequest();
_urlRequest.url="javascript:window.open('"+url+"','"+title+"','width="+width+",height="+height+", resizable="+resize+"');newWindow.focus(); void(0);";
navigateToURL(_urlRequest,_window);
}
Código :
package com.cristalab.utils
{
import flash.net.URLRequest;
import flash.net.navigateToURL;
public class PopUp
{
private var _url:String = "http://www.cristalab.com";
private var _width:Number= 400;
private var _height:Number= 300;
private var _title:String = "title";
private var _resize:String = "yes";
private var _window:String = "_blank";
public function PopUp()
{
}
public function openWindow(newUrl:String = null):void{
if(newUrl)
this.url = newUrl;
var _urlRequest:URLRequest=new URLRequest();
_urlRequest.url="javascript:window.open('"+url+"','"+title+"','width="+width+",height="+height+", resizable="+resize+"');newWindow.focus(); void(0);";
navigateToURL(_urlRequest,_window);
}
public function set url(val:String):void
{
_url = val;
}
public function get url():String
{
return _url;
}
public function set width(val:Number):void
{
_width = val;
}
public function get width():Number
{
return _width;
}
public function set height(val:Number):void
{
_height = val;
}
public function get height():Number
{
return _height;
}
public function set title(val:String):void
{
_title = val;
}
public function get title():String
{
return _title;
}
public function set resize(val:String):void
{
_resize = val;
}
public function get resize():String
{
return _resize;
}
public function set window(val:String):void
{
_window = val;
}
public function get window():String
{
return _window;
}
}
}
Código :
import com.cristalab.utils.PopUp;
var t:PopUp = new PopUp();
btn1.addEventListener(MouseEvent.CLICK, popUpNormal);
btn2.addEventListener(MouseEvent.CLICK, popUpEditado);
function popUpNormal(e:MouseEvent):void {
var ir:String;
ir="http://www.cristalab.com/tutoriales/";
t.openWindow(ir);
}
function popUpEditado(e:MouseEvent):void {
t.url="http://www.google.com";
t.title="Estamos en Google";
t.width=640;
t.height=480;
t.resize="yes";
t.window="_self";
t.openWindow();
}
Código :
package com.cristalab.utils
{
import flash.net.URLRequest;
import flash.net.navigateToURL;
public class PopUp
{
public var _url:String = "http://www.cristalab.com";
public var _width:Number= 400;
public var _height:Number= 300;
public var _title:String = "title";
public var _resize:String = "yes";
public var _window:String = "_blank";
public function PopUp(){
}
public function openWindow(newUrl:String = null):void{
if(newUrl)
this.url = newUrl;
var _urlRequest:URLRequest=new URLRequest();
_urlRequest.url="javascript:window.open('"+url+"','"+title+"','width="+width+",height="+height+", resizable="+resize+"');newWindow.focus(); void(0);";
navigateToURL(_urlRequest,_window);
}
}
Código :
var t:PopUp = new PopUp();
function popUpEditado(e:MouseEvent):void {
t.url="http://www.google.com";
t.title="Estamos en Google";
t.width=640;
t.height=480;
t.resize="yes";
t.window="_self";
t.openWindow();
}
eldervaz :
nico-blog :