Showing posts with label Flash. Show all posts
Showing posts with label Flash. Show all posts

Friday, January 28, 2011

IE throw null object exception when flash call javascript function

用open flash chart第一次正常载入一个图表到页面之后,当使用jQuery.fn.empty()方法移除此图表时,IE中会抛出一个错误,其他浏览器都是正常的,内容如下:


JScript - script block, line 1 character 124
'null' is null or not an object

通过IE8的debug工具可以看到出错时,javascript正在执行的代码如下:

try { document.getElementById("report-charts").SetReturnValue(__flash__toXML(ofc_resize([66,-96,66,-87])) ); } catch (e) { document.getElementById("report-charts").SetReturnValue("<undefined/>"); }

这个并不是页面中的javascript代码,应该是flash中调用外部javascript方法时,所使用的javascript代码,在IE8中断点调试,可以发现document.getElementById("report-charts")的结果为null,所以抛出了以上错误。
避过此问题的办法是在陊除已经载入的图表时,不调用jQuery.fn.empty()方法,而是直接使用jQuery.fn.html(''),将flash所在父元素的内容置空:

$('#report-charts').parent().html('');
// 如果使用$('#report-charts').parent().empty();在IE中则会报错
// ... 重新生成report-charts对象并载入新的flash图表
swfobject.embedSWF(ofc, "report-charts", "100%", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_chart_0"});

Thursday, January 27, 2011

Open Flash Chart IO ERROR Loading test data Error #2032

在IE6中使用open flash chart2加载图表的json数据时,第一次载入数据,图表渲染正常,第二次就会报一个错误,提示数据加载错误:


Open Flash Chart
IO ERROR
Loading test data
Error #2032

而在其他的浏览器,如IE8/firefox/chrome中都是正常的,在网上搜索了一些回答,其中有人提到说这是因为浏览器的缓存造成的问题,只要在用swfobject加载open-flash-chart.swf时,在url后面加上一个动态参数,让浏览器不要使用本地缓存:

swfobject.embedSWF("open-flash-chart.swf?t=" + (new Date()).getTime(), "charts-div-id", "100%", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_chart_0"});


References: Open Flash Chart IO ERROR Loading test data Error #2032

Monday, February 04, 2008

Using javascript copy text string to user's clipboard

1、System.setClipboard() 方法允许 SWF 文件用纯文本字符串替换剪贴板内容。这不会带来任何安全性风险。为避免因剪切或复制到剪贴板的密码和其它敏感数据所带来的风险,FLASH AS3并未提供相应的“getClipboard”(读取)方法。


if (clipboard.length)
{
System.setClipboard(clipboard);
}

2、JavaScript调用FLSAH里设置的回调方法,将文本内容clipboard传给FLASH,由FLASH完成copy到剪贴板的动作。
另在IE7里操作剪贴板会有提示框警告。

Friday, January 18, 2008

getURL and ExternalInterface.call of flash invoke javascript function

在Flash中,通过getURL("javascript:urchinTracker(pageUrl2);")方法调用GA的JS,从而跟踪FLASH的内部一些帧,当在flash相同的一帧里,此getURL()方法前还有一个getURL("javascript:urchinTracker(pageUrl1);")方法时,此时后面那个pageURL2是不会被访问的,也就是后面的JS不会被执行,可以将2个JS并到一个getURL()方法里去执行,另外用flash中的ExternalInterface.call()方法可以直接调用外部JS从避过此问题.

Tuesday, August 21, 2007

HTML pass parameters to Flash AS3


<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="Example" width="100%" height="100%"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
<param name="movie" value="Example.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#dddddd" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="FlashVars" value="foo=1&bar=2" />
<embed src="Example.swf"
quality="high"
bgcolor="#dddddd"
width="50%"
height="50%"
name="Example"
align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
FlashVars="foo=1&bar=2"
>
</embed>
</object>

param中的FlashVars可以传参数给IE中的Flash(其他参数也是,如宽高),embed中的FlashVars可以传参数给Firefox中的Flash(其他参数也是,如宽高)。
AS3中可以这样接收传进来的参数,如

var foo:String = root.loaderInfo.parameters.foo;
var request:URLRequest = new URLRequest("http://localdomain/get.php?foo=" + foo);
var loader:URLLoader = new URLLoader();
loader.load(request);

这里如果get.php是个中转页,则需要设置cache无效,不然第一次重定向有效,后面的会不生效了(这里有个恶心的地方,Firefox只要在这个中转页上加了就可以每次刷新重定向,IE则需要在重定向目标页面也要加上这个头信息说明Cache无效才能每次刷新也重定向生效)。不过这个对于静态页面写了META标签也是不行。
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

Wednesday, July 04, 2007

Rails中的flash[:notice]错误使用的提示


NoMethodError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.size):
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/cgi_process.rb:228:in `set_content_length!'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/cgi_process.rb:187:in `out'
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process'
c:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243
c:/ruby/bin/mongrel_rails:16:in `load'
c:/ruby/bin/mongrel_rails:16


如果没有赋值给flash[:notice],直接在View里调用抛出上面的错误,因为flash[:notice] = nil。