---
title: "flex与flash的fscommand通信"
author: "eto95eto"
date: "2012-07-01T09:21:04Z"
tags: []
categories: ["非技术"]
slug: "flex-flash-fscommand"
draft: false
lastmod: "2012-07-01T09:21:04Z"
id: 1572619
url: "https://eto95eto.iteye.com/blog/1572619"
---

为了业务需要，最近利用Flex来重写我们公司客户端（c++写）的课件播放器。在写的过程中遇到一个问题，就是在播放课件时候，需要加载外部flash，同时，播放器还要能与该flash进行通信。查了相关资料，外部加载一些动作会发出fscommand的消息，所以，打算通过fscommand -> javascript -> flex(actionscript)。所以，这里面就有两步需要处理：    
　　第一步：javascript响应fscommand消息。在网页的页面中需要增加如下脚本：                     这段VBScript很重要，当时，我就没有加这段VBScript代码，导致在IE中就是不响应fscommand。其中etplayer是指加载页面中的flash对象ID号。在这段代码中有个call ，所以，还需要增加这个call调用的函数           function etplayer_DoFSCommand(command, args){ if(command == "quiz"){ etplayer.setUserAnswer(args); } if(command == "exam"){ etplayer.setUserAnswer(args); } }  第二步：在上面javascript代码中，setUserAnswer函数是flex通过ExternalInterface的addCalback方式注册的函数，这样通过javascript中介，实现了flex响应flash的fscommand消息。