2011-09-29 1 views
0

그래서 기본적으로 내 이벤트와 구성 요소가 전달이 : 나는 디버그를 통해 이동하는 경우flex에서 함수 실행을 변경/우선 순위 지정하는 방법은 무엇입니까?

private function myDispatchedEvent(event:Event):void 
{ 
    //Here I have my static function with title and handler function showConfirmation 
     Calculate.showConfirmation("String Title", function(event:Close):void 
     { 
      if(bla bla bla) 
      //lots of code etc. ... 
     }); 
//myDispatchEvent function continues here.. 
} 

그래서 문제는, 내 정적 함수의 showConfirmation 핸들러입니다 : 스크립트 태그에서

<components:MyComp id="Id" myDispatchedEvent(event)/> 

내가 그 기능이 , 그냥 그 함수를 건너 뛰고 myDispatchedEvent를 계속합니다. showConfirmation 함수 내의 익명 함수가 실행되지 않는 이유는 무엇입니까?
감사합니다.

+0

익명의 함수가 호출 된 코드를 표시 할 수 있습니까? 이 코드만으로는 실행되지 않는 이유를 알 수 없습니다. – RIAstar

+0

Calculate.showConfirmation ("문자열 제목", 함수 (이벤트 : 닫기)) : void { if (bla bla bla) // 많은 코드 등 ... }); 그것이 실행되는 곳입니다. 쉽게 별도의 함수를 작성할 수 있습니다 : Calculate.showConfirmation ("String Title", myNewSeparateFunction), 그것은 중요하지 않습니다, 그것은 여전히 ​​호출되지 않습니다. – randomUser56789

답변

2

함수는 호출시 실행됩니다. 당신의 경우에는 당신은 그것의 선언을 가지고 있습니다. 이 함수를 Calculate.showConfirmation의 어딘가에서 호출하면 실행됩니다. 다음과 같은

뭔가 :

public class Calculate 
{ 
    public static function showConfirmation(title:String, func:Function):void 
    { 
     // The call I'm talking about is here 
     func(new Close()); 
    } 
} 
+0

다음과 같은 의미가 있습니다 : Calculate.showConfirmation ("String Title", myNewSeparateFunction) 그리고 어딘가에 : private function myNewSeparateFunction (event : Close) : void {// code}? – randomUser56789

+0

내 대답에 코드를 추가했습니다 – Constantiner

+0

제안을 잘 이해하지 못합니다. Calculate 클래스에는 다른 정적 함수 showConfirmationImpl을 호출하는 showConfirmation 함수가 있습니다. 나는 아직도 전화가 안되는 이유를 이해하지 못합니다. myDispatchedEvent (start) -> showConfirmation-> showConfirmationImpl-> 익명 function-> myDispatchedEvent (end)와 같아야합니다. 그러나 지금은 다음과 같습니다. myDispatchedEvent (start) -> myDispatchedEvent (end) -> showConfirmation-> showConfirmationImpl-> 익명 함수. – randomUser56789

1

내가 무엇을 당신이하려는 것은 매우 이상하다 먼저 가정 해 봅시다. 나는 다른 해결책을 코드하려고 노력할 것이지만, 이것은 당신이하려고하는 것에 달려있다. 우리는 목표에 도달하는 더 좋은 방법을 찾을 수있는 것에 대해 더 많이 알려줍니다. 여러분은 다음과 같이 할 수 있습니다 :

<?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" 
       minHeight="600" minWidth="955"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.events.CloseEvent; 

      public static function myFunction(param:String, func:Function):void { 
       trace("executing"); 
       func.apply(); 
      } 

      protected function labelx_clickHandler(event:MouseEvent):void { 
       trace("click"); 
       Tests.myFunction("Test", function():void { 
        if (event.localX > 0) { 
         trace("Test"); 
        } 
        else { 
         trace("No"); 
        } 
       }); 

      } 
     ]]> 
    </fx:Script> 
    <s:Button id="labelx" 
       label="Click me" 
       click="labelx_clickHandler(event)"/> 
</s:Application> 

Constantiner에서 이미 말한 것과 비슷한 점이 있습니다. 이 정적 함수 내에서 정적 함수로 전달하는 함수를 매개 변수로 실행하지 않으면 실행되지 않습니다.

관련 문제