0

Flex 4.1 でコンパイルされた Flex アプリケーションがあります。

そのフレックス アプリケーションに、変数スコアを含む swf をロードさせたいのですが、この変数を変更できるようにしたいと考えています。

私は 2 つのバージョンの swf を作成しました。1 つは as2 コードでコンパイルし、もう 1 つは as3 コードでコンパイルしました。

これは私のフレックスアプリケーションです:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

<fx:Script>
<![CDATA[

        import mx.events.FlexEvent;
        import mx.managers.SystemManager;

private var loadedSM:SystemManager;

private function initNestedAppProps():void
{
loadedSM = SystemManager(ufkLoader.content);
loadedSM.addEventListener(FlexEvent.APPLICATION_COMPLETE,updateNestedLabels);
}

private function updateNestedLabels(e:Event):void {
loadedSM.application["score"]=500;
}

]]>
</fx:Script>
<mx:SWFLoader  loadForCompatibility="true" width="500" height="500" creationComplete="initNestedAppProps()" id="ufkLoader" source="http://127.0.0.1/path/to/swf.swf" />
</s:Application>

127.0.0.1 (同じドメイン) のブラウザーでフレックス アプリケーションを実行すると、次のエラーが表示されます。

An ActionScript error has occurred:
TypeError: Error #1034: Type Coercion failed: cannot convert Main__Preloader__@f36e6191 to mx.managers.SystemManager.
at Main/initNestedAppProps()
at Main/__ufkLoader_creationComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.core::UIComponent/set initialized()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()

as3 または as2 コードを実行しようとすると、この種のエラー メッセージが表示されます。

Google で確認したところ、フラッシュ アプリケーションの場合、システム マネージャーを使用する必要はなく、SWFLoader.content をオブジェクトとしてキャストし、そこから関数を呼び出してみる必要があると書いている人もいました。

したがって、次のコードを使用します。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

<fx:Script>
<![CDATA[
private function updateNestedLabels(e:Event):void {
trace("HERE");
ufkLoader.content['score']=500;
}
]]>
</fx:Script>
<mx:SWFLoader  loadForCompatibility="true" width="500" height="500" complete="updateNestedLabels(event)" id="ufkLoader" source="http://127.0.0.1/~ufk/work-projects/xpofb/flash/toolkit-test/scores/as3/score.swf" />
  </s:Application>

as3 バージョンを実行すると、次のエラーが表示されます。

An ActionScript error has occurred:
ReferenceError: Error #1056: Cannot create property score on Main__Preloader__.
at Main/updateNestedLabels()
at Main/__ufkLoader_complete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.controls::SWFLoader/http://www.adobe.com/2006/flex  /mx/internal::contentLoaderInfo_completeEventHandler()

as3バージョンを実行すると、次のエラーが発生します。

An ActionScript error has occurred:
ReferenceError: Error #1056: Cannot create property score on flash.display.AVM1Movie.
at Main/updateNestedLabels()
at Main/__ufkLoader_complete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.controls::SWFLoader/http://www.adobe.com/2006/flex/mx/internal::contentLoaderInfo_completeEventHandler()

私の as2 swf ファイルには、score_text という名前のテキスト要素と、最初で唯一のフレームに次のコードが含まれています。

var score:Number = 0;

function setScore() {
  score++;
  score_text.text=score.toString();
}

function addToScore(num:Number) { 
  score+=num;
  setScore();
}
setInterval(setScore,1000);

私の as3 フラッシュ ファイルには、Main というメイン クラスと、score_text という同じテキスト要素が含まれています。

メインクラス:

package  {

import flash.display.MovieClip;
import flash.utils.setInterval;

public class Main extends MovieClip {
public var score:Number = 0;

public function setScore() {
score++;
score_text.text=score.toString();
}

public function addToScore(num:Number) {  
score+=num; 
setScore();
}

    public function Main() {
    setInterval(setScore,1000);     
    }
}

}

何か案は?

4

1 に答える 1

0

これはあなたが望むことだと思います:

package  {

import flash.display.MovieClip;
import flash.utils.setInterval;

public class Main extends MovieClip {
    private var _score:Number = 0;

    public function set score(value):void {
       _score = value;
       score_text.text=score.toString();
    }

    public function addToScore(num:Number):void {  
        score+=num; 
    }


    public function Main() {

    }
}

} 
于 2011-06-23T18:19:50.027 に答える