请问下,VC怎么和Flash(.swf格式)进行交互?怎么设置Flash中定义的变量值?
我用以下方法,好像不起作用。
   CShockwaveFlash *m_pFlashPlayer = NULL; 
   ......
   m_pFlashPlayer->SetVariable("myText","11111");  在Flash中怎么定义变量,才可以支持写myText的值?但是:
  Cstring ss=m_pFlashPlayer->GetVariable("myText");
用这个读取能成功,不知道怎么回事?非常苦恼,望请赐教!

解决方案 »

  1.   

    m_pFlashPlayer->SetVariable("myText","11111");
    这个函数调用失败,GetLastError()返回值什么?
      

  2.   

    Flash9.ocx在"VC开发环境"中,选择"工程"->"添加工程"->Components and controls->..\programFiles\Microsoft Visual Studio\Common\MSDev98\Gallery\Registered ActiveX Controls选择"shockware Flash Object.lnk",添加Flash控件。在Flash.h中#include "shockwaveflash.h"
    class CFlash : public CDialog
    {    ……public:
    //------------Flash文件---------------
         char PathName[255];// 保存flash文件名
    void FlashRun();     //*.swf文件运行
    void FlashPause();   //*.swf文件暂停
         void FlashStop();    //*.swf文件停止 
    long lMSEL;   //定义总的播放毫秒数
    long   CurrentNum;   //保存当前的帧数CurrentFrame()
    //     long CMSEL;   //定义当前的已经播放的时间
         ……
    }在Flash.cpp中long   i_TotalNum=0;   //保存总帧数GetTotalFrames()
    long   CMSEL=0;        //定义当前的已经播放的时间//--------------*.swf----
    void CFlash::FlashRun()
    {
    long state=0;
    UpdateData(FALSE);
        
    CMSEL=0;//定义当前的已经播放的时间CurrentNum=0;
    m_FlashOCX.LoadMovie(0,PathName);
    state=m_FlashOCX.GetReadyState();
    m_FlashOCX.Zoom(0);//还原大小,显示全部的内容// long lMSEL=0;   //定义总的播放毫秒数
    if(state==4)
    {
       m_FlashOCX.GotoFrame(0);
       CurrentNum=m_FlashOCX.CurrentFrame();
       i_TotalNum=m_FlashOCX.GetTotalFrames();
       m_FlashOCX.GotoFrame(CurrentNum);   lMSEL=i_TotalNum;   //得到总的毫秒数,将总帧数转换为毫秒数
       m_FlashOCX.Play();//播放
       SetTimer(3,10,NULL);
    }
    }void CFlash::FlashPause()
    {
    m_FlashOCX.Stop(); //在当前帧位置停止播放
    KillTimer(3);
    }void CFlash::FlashStop()
    {
       KillTimer(3);
    m_FlashOCX.GotoFrame(m_FlashOCX.GetTotalFrames()-1);//移动到最后一帧
    m_FlashOCX.Stop();        //在末尾停止播放
       m_FlashOCX.Zoom(0);//还原大小,显示全部的内容
    m_FlashOCX.SetBGColor("0");
    }void CFlash::OnTimer(UINT nIDEvent) 
    {
    // TODO: Add your message handler code here and/or call default
    int oldNum=CurrentNum;
    CurrentNum=m_FlashOCX.CurrentFrame();
    if(oldNum!=CurrentNum)
         CMSEL=CMSEL+1;   //保存现在已经播放的时间数if(CurrentNum>=i_TotalNum-1)
    {   FlashStop();      /*m_FlashOCX.StopPlay();*/ }
    else
    {
            if(CMSEL>=lMSEL)     //lMSEL为总的播放时间,CMSEL为当前已经播放的时间数
               FlashStop();
         else
         {   
                 m_FlashOCX.Zoom(0);//还原大小,显示全部的内容
          if(m_FlashOCX.IsPlaying()==FALSE)//判断*.swf文件是否正在播放
          {       m_FlashOCX.Play();      }
         }
    }
    CDialog::OnTimer(nIDEvent);
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////“播放”按钮代码:
        flash.Play();
        
        “暂停”按钮代码:
         flash.Stop();
        
        “停止”按钮代码:
         flash.Rewind();    
       flash.Stop(); 
      
      “重播”按钮代码:
    flash.Rewind();
    flash.Play();
      
      “后退”按钮代码:
    flash.Back();
      
      “前进”按钮代码:
    flash.Forward();
      
      “末帧”按钮代码:
       flash.GotoFrame(flash.get_TotalFrames()-1); 
    “快退”按钮代码:
       int current=flash.CurrentFrame();
       if(current>4)
       {
       current-=5;
       flash.GotoFrame(current);
       }
       else
       {
       flash.put_FrameNum(0);
       }  “快进”按钮代码:
       int current=flash.CurrentFrame();
       int i=flash.get_FrameNum();
       if(current<flash.get_TotalFrames()-5)
       {
       current+=5;
       flash.GotoFrame(current);
       }
       else
       {
       flash.put_FrameNum(flash.get_TotalFrames()-1);
       }  “放大”按钮代码:
       flash.Zoom(50);  “缩小”按钮代码:
       flash.Zoom(200);   
      

  3.   

    m_pFlashPlayer->SetVariable("myText","11111");可以成功返回,可是在与vc交互的flash动画中的脚本myText变量值并没有变化,怎样才能控制在给flash中的脚本变量后,脚本才可以运行?谁有思路。
      

  4.   

    宿主程序与Flash交互的时候一定要注意时间的契合,就是宿主程序要与Flash的时间轴(脚本)要设计好。
      

  5.   

    Vc 程序 和flash 的变量传递 通信 1、Flash 向 vc程序发送信息 使用 FSCommand 在flash 中 在需要发送信息的事件中使用 FSCommand   Vc 程序窗体中添加 CShockwaveFlash m_Flash; 并添加事件处理  void CDialogFlashTest::OnFSCommandShockwaveflash1(LPCTSTR command, LPCTSTR args)  {  // TODO: Add your control notification handler code here    }如:flash 中 FSCommand(”a”, ”b”);Command为 a;Args 为 b;  2、VC 向 FLASH 程序发送信息 Flash 中 第一个关键帧中 添加代码loadVariables(“xxx”,0);第一个参数随便。第二个关键帧中添加动态文本设置变量为 a; 在vc代码中添加m_Flash.SetMovie("c:\\12.swf");  m_Flash.Play();  m_Flash.SetVariable("a","3.6"); flash第二帧中的动态文本会显示3.6;
      

  6.   

    主程序与Flash交互的时候一定要注意时间的契合,就是宿主程序要与Flash的时间轴(脚本)要设计好。