Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I followed this guide to create a new JS to flash communication.(我按照本指南创建了一个用于通讯的新JS。)

My code is(我的代码是) function getID( swfID ){ if(navigator.appName.indexOf("Microsoft") != -1){ me = window[swfID]; }else{ me = document[swfID]; } } function js_to_as( str ){ me.onChange(str); } However, sometimes my onChange does not load.(但是,有时我的onChange无法加载。) Firebug errors with(萤火虫错误) me.onChange is not a function(me.onChange不是一个函数) I want to degrade gracefully because this is not the most important feature in my program.(我想优雅地降级,因为这不是我程序中最重要的功能。) typeof gives the same error.(typeof给出相同的错误。) Any suggestions on how to make sure that it exists and then only execute onChange ?(关于如何确保它存在然后仅执行onChange任何建议?) (None of the methods below except try catch one work)((以下任何一种方法都不能尝试抓到一件作品))   ask by Alec Smart translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try something like this:(尝试这样的事情:)

if (typeof me.onChange !== "undefined") { // safe to use the function } or better yet (as per UpTheCreek upvoted comment)(或更好(根据UpTheCreek的评论)) if (typeof me.onChange === "function") { // safe to use the function }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...