2009년 12월 7일 월요일

Html >> Flex Binding Html 값 넘기는 방법|작성자 서기



일반 html 에서 flex가 있는 html로 값을 넘기는 방식이다~!

무슨 소린가 하니..

test.html (flex 가 없는 html) 에서
www.aaa.com?index=2 (aaa.com은 all flex 로 만들어진 페이지)
같은 방식으로 넘겼을때 index = 2 << 이 데이터를 받는 방식이다..

이건 post 방식은 안되고...순수하게 get 방식만 된다~! post 방식과 get 방식을 모르시는 분은 패스 ㅡㅡ;



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<script type="text/javascript">
    function test(){
        window.open("http://localhost:8080/aaa/index.html?index=1","333","width=1000, height=500");
        }
</script>
<body>
<input type="button" onclick="test()"/>
</body>
</html>

이건  test.html 문서이다

보면 <input type="button" onclick="test()"/> 이것만 있다..

버튼 눌렀을때 팝업창 띄우는 html;;

flex 로 가보장~!

빌더를 쓰시는 분들은 모두 html-template 라는 폴더가 있을텐데..

그 안으로 들어가보자..

그럼 index.template.html 이라는 html 문서가 있다

index.template.html 파일은

mxml 플렉스 파일을 컴파일 시키면 기본으로 bin-debug 폴더에 컴파일이 된다..

컴파일 되서 나오는 파일중에 html, swf ,js 가 있는데 이중 html파일에 어떤걸 작업 하고 싶을때
index.template.html에 써주게 되면

컴파일 시키더라도 써준 값이 나온다(이건 해보시면 알듯 -_-)

그럼 index.template.html을 열고

<body scroll="no">
이런 부분 아래 script 가 있는데 거기다

var tmp=window.location; //호출된 현재창의 주소
    tmp=String(tmp).split('?'); //? 이후가 배열에 담김
라고 적어주자..
html 끼리의 통신 방법은 없기 때문에
저렇게 임의로 배열을 만들어 주는것이다

그럼
http://localhost:8080/aaa/index.html,index=1

이렇게 나올것이다

tmp[0] = http://localhost:8080/aaa/index.html;
tmp[1] = index=1;

그럼 swf 에 넘겨주자..

mxml 에서 parameter를 받는 방식은
Application.application.parameters << 이런 방식으로 받는데
ex) a.swf?index = 1  으로 넘기면 mxml에서는  Application.application.parameters.index; 라고 하면 1이 나온다

따라서 swf 에 값을 넘겨주어야 한다

index.template.html << 파일에서
AC_FL_RunContent 을 찾는다
두개가 나올텐데
else if (hasRequestedVersion) { .....

가 있는곳으로 간다

  "src", "${swf}",
            "FlashVars", tmp[1],
            "width", "${width}",
            "height", "${height}",
            "align", "middle",
            "id", "${application}",
            "quality", "high",
            "bgcolor", "${bgcolor}",
            "name", "${application}",
            "allowScriptAccess","sameDomain",
           "type", "application/x-shockwave-flash",
            "pluginspage", "http://www.adobe.com/go/getflashplayer"

이렇게 되어 있을텐데 저 빨간색 부분은 없을것이다
FlashVars 를 추가 하면
http://localhost:8080/aaa/index.swf?index=1;
이런 방식으로 넘어가는것이다

그럼 Application 에서

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="350" creationComplete="ainit()">
 <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
       
            public function ainit():void{
                Alert.show(Application.application.parameters.index);
            }

    </mx:Script>
</mx:Application>
으로 받으면 제대로 1이라는 값이 나온다..

html에서 flex로 값을 넘기는 방식은 많다

쿠키를 이용해서 넘기는 방식도 있을테고

많이 쓰는 ExternalInterface 를 사용해서 넘기는 방식도 있을것이다..

저건 좀 쉬운 방식이라서 적어둔다 ㅎㅎㅎ

PS1 : 값을 여러개 넘기게 될경우에는 좀더 수정 해야해요~ 오~! 잘되네욤 -_-;;
PS2 : POST 방식은? ㅡㅡ?


댓글 없음:

댓글 쓰기