2011-05-12 3 views
2

사용자가 버튼을 클릭 할 때 무언가를 확인하는 기능이 있습니다. 무언가가 발견되면 발견되었음을 알리는 경고가 나오고,이를 허용 할 것인지 묻습니다. 또는 무언가를 발견하게하는 행동을 취소합니다. 코드는 다음과 같습니다flex 3 : 알림 창을 사용하여 값을 함수로 전달

Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer); 

눌러에 "예"또는 "아니오"라고 할 것이다 conflictAnswer 기능은 ... 그것은 다음과 같습니다

private function conflictAnswer(event:CloseEvent):void 
{ 
    if (event.detail == Alert.YES) 
    { 
     Alert.show(
    } 
} 

내 질문은 이것입니다, 어떻게 Alert를 표시하는 함수에 포함 된 변수를 전달합니까? 나는 이런 식으로 시도했다 :

Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer(Event, var1, var2)); 


private function conflictAnswer(event:CloseEvent, varA, varB):void 
{ 
    if (event.detail == Alert.YES) 
    { 

    } 
} 

그러나 작동하지 않았다.

아무도 도와 줄 수 있습니까?

answers[0] = cPositions[i][0]; 
answers[1] = cPositions[i][1]; 
var anAlert:Alert = Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer); 
anAlert.data = {answers:Array}; 

을 다음 conflictAnswer 기능은 다음과 같습니다 :

감사 Brds

편집 최초의 응답을 읽은 후, 나는이 함께 왔어요

private function conflictAnswer(event:CloseEvent):void 
{ 
    var projectID:Number = event.currentTarget.answers[0]; 
    var positionID:Number = event.currentTarget.answers[1]; 
    if (event.detail == Alert.YES) 
    { 
     Alert.show(String(projectID + " | " + positionID)); 
    } 
} 

하지만이 i 작동하지 마세요 ... 어떤 아이디어?

답변

3

Alert.show() 당신이 당신의 데이터를 설정할 수 있습니다 data 필드가 경고 인스턴스를 반환

var anAlert:Alert = Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer); 
anAlert.data = {var1:var1, var2:var2}; 

그런 다음 이벤트 처리기에서 당신은 당신의 데이터 객체 얻을 수 있습니다 : 코드에 대한

var myData:Object = event.currentTarget.data; 
var var1:Object = myData.var1; 
var var2:Object = myData.var2; 

를 그것은 것입니다 다음과 같이 보입니다.

answers[0] = cPositions[i][0]; 
answers[1] = cPositions[i][1]; 
var anAlert:Alert = Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer); 
anAlert.data = {answers:answers}; 

그 다음 :

private function conflictAnswer(event:CloseEvent):void 
{ 
    var projectID:Number = event.currentTarget.data.answers[0]; 
    var positionID:Number = event.currentTarget.data.answers[1]; 
    if (event.detail == Alert.YES) 
    { 
     Alert.show(String(projectID + " | " + positionID)); 
    } 
} 
+0

나는 당신이 나를 도와주기 위해 당신이 응답했던 것을 사용하는 방법을 정말로 모르고있다. 네가하는 말을 이해한다. 어떻게해야할지 모르겠다. 나는 Alert.show 콜을 가지고있다 ... 그 안에 데이터를 설정할 수 있습니까? Alert.show는 원래 질문에 표시됩니다. – Brds

+0

"Alert.show()가 경고 인스턴스를 반환합니다"라는 말의 의미를 명확히하기 위해 추가 답변을 추가했습니다. – Constantiner

+0

나는 몇 가지 질문이 있습니다. 원래 게시물 – Brds

관련 문제