2009-12-08 5 views
0

플래시 용 액션 스크립트를 코딩하는 것은 이번이 처음입니다. 다른 플래시 클립의 부모 역할을하는 플래시 클립을 작성하고 싶습니다. 부모 플래시에 함수를 작성하고 해당 함수를 하위 플래시 클립에서 호출하려고합니다. 예를 들어 "submitscore.php"에 게임 점수를 보내는 actionscript를 만들고 싶습니다. 부모는 단지 컨트롤러이고 아이는 내 게임입니다. 내가 게임 점수를 컨트롤러에 보내고, 다음 그것을 내 PHP 파일로 보내고 싶다. 샘플 코드 또는 그 일을 할 수 있습니까? 내게 처음이기 때문에 내가 원하는 것이 무엇인지 알기가 어렵습니다.) 사전에 고맙습니다.플래시 액션 스크립트

답변

1
var game:Object; 
private function sendToPHP(e:CustomEvent):void 
{ 
    var score:Number = e.score; 
    //send it 
} 
//load the game.swf 
var ldr:Loader = new Loader(); 
addChild(ldr); 
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad); 
ldr.load(new URLRequest("Game.swf")); 

private function onLoad(e:Event):void 
{ 
    game = LoaderInfo(e.target).content; 
    game.addEventListener("sendScore", sendToPHP); 
} 

//Game.as 
//call this whenever you want to send score to php 
dispatchEvent(new CustomEvent("sendScore", score)); 

/** 
* CustomEvent.as should extend Event and its constructor should update the public 
* property score:Number and call super() with the first parameter. 
* Feel free to ask if you have any doubts implementing custom events. 
* */ 
+0

고맙습니다. 하지만 내 작업 스크립트에서이 코드를 작성했기 때문에 더 자세한 정보를 작성하는 것이 가능하며 클래스에없는 함수에 대해서는 3 가지 오류가있었습니다. 나는 정말로 초보자 다. 고맙습니다. – AliBZ

+0

문서 클래스를 선언하고 그 안에 함수를 작성해야합니다. 오류 메시지가 정확히 무엇입니까? 코드는 AS3입니다. – Amarghosh

+1

AS1로 작성할 수 있습니까? – AliBZ

관련 문제