2011년 3월 10일 목요일
2011년 3월 3일 목요일
2010년 7월 18일 일요일
FLEX
1. ComboBox 선택 이벤트 발생 시키기
comboBoxName.selectedIndex=2;
comboBoxName.dispatchEvent({ type: "change" });
참고 사이트 : http://blog.naver.com/lmy20?Redirect=Log&logNo=20022755755
이 글은 스프링노트에서 작성되었습니다.
2009년 12월 7일 월요일
Html >> Flex Binding Html 값 넘기는 방법|작성자 서기
[출처] 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><![CDATA[
import mx.controls.Alert;
public function ainit():void{
Alert.show(Application.application.parameters.index);
}
</mx:Script>
으로 받으면 제대로 1이라는 값이 나온다..
html에서 flex로 값을 넘기는 방식은 많다
쿠키를 이용해서 넘기는 방식도 있을테고
많이 쓰는 ExternalInterface 를 사용해서 넘기는 방식도 있을것이다..
저건 좀 쉬운 방식이라서 적어둔다 ㅎㅎㅎ
PS1 : 값을 여러개 넘기게 될경우에는 좀더 수정 해야해요~ 오~! 잘되네욤 -_-;;
PS2 : POST 방식은? ㅡㅡ?
ValueObject 프로퍼티 찾기 for in|작성자 서기
[출처] ValueObject 프로퍼티 찾기 for in|작성자 서기
Flex에서 dynamic Object의 property를 찾기는 샘플도 많고 많이 나왔다..
for in 을 쓰라고...
무엇인가 하니
var obj:Object = {name="장윤석", age="19"};
for (var name:String in obj){
trace(obj[name]);
}
이라고 하면
콘솔창엔 차례로
name
age
가 나올것이다
| for..in | Iterates over the dynamic
properties of an object or elements in an array and executes
statement for each property or
element. |
설명서에도 dynamic properties 를 찾는다고 했으니까
하지만 Flex에서는 java 와 같이 ValueObject를 쓸때가 많다
Class TestVO{
public var name:String;
public var age:String;
}
이런 클래스..(보통 RemoteObject에서 나온 VO 값을 Flex에서 사용하기 위해 많이 쓴다)
저 property를 모를때...
어떻게 찾아야 할까? 이런것들은 많이 나와있지 않다..
똑같이
var vo:TestVO = new TestVO();
vo.name = "장윤석";
vo.age = 19"
for (var name:String in vo){
trace(name);
}
을 하면 될까?
안된다
for 문 안에도 안들어 갈것이다..(심심하신 분들은 Test 해보세요~)
그럼 저 properties을 어떻게 찾아야 하나....
방법은 있다..
var vo:TestVO = new TestVO();
vo.name = "장윤석";
vo.age = 19";
var obj = ObjectUtil.getClassInfo(vo);
for each(var name:String in obj.properties){
trace(name);
}
이러면 끝
getClassInfo()라는 것이 해당 클래스의 정보를 넘겨준다
name,alias,properties 등등
이것때메 어제 야근 ㅠㅠ
이제 VO도 동적으로 가져올때 저런방식으로 찾자~!
Flex의 다국어 !!!!(Localization)|작성자 서기
[출처] Flex의 다국어 !!!!(Localization)|작성자 서기
얼마전 프로젝트를 하면서 Tour de Flex 를 다운받은적이 있다..
이것저것 보는데
Localization 이라는게 있는것이다
플젝 하면서 다국어 버전을 만들라고 요청 온적이 있었는데..
우리는 그냥 Localizer.as 파일을 만들어서 일일히 변환 해주는 노가다를 했었다(물론 xml로 언어는 가져오지만 그래도 좀...)
Localization을 보니 플랙스에서 가지고 있는 locale을 바꿔 주는것이다..
오~! 이런 획기적인?
그래서 한번 찾아봤다..
Flex 3:Feature Introductions: Runtime Localization
오 이런게? 흠....
보면 알겠지만 (사실 나도 영어는 딸려서...)
fr_FR, en_US 버전 두개를 만들어 언어
변환을 해주는것이다그럼 TEST 시작..
일단 en_US의 카피 본이 필요 하다
자신이 설치한 Flex Builder 에 가보면
난 디폴트로 설치를 해서 경로가 C:\Program Files\Adobe 이곳이다
그럼 기본으로 Flex 가 가지고 있는 locale 을 알아보자
C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0\frameworks\locale
으로 들어가보자
경로는 Bulider 설치 폴더\sdks\3.2.0\frameworks\locale 이다
그럼 en_US,ja_JP 폴더 두개가 있을것이다..
이게 플렉스에서 가지고 있는 두가지 버전의 locale 이다...하난 영어,하는 일어..(췟)
난 한국사람이기 때문에 영어,한국어 두가지의 locale 버전을 만들것이다..
그럼 기본으로 가지고 있는 locale 을 카피 한다
도스창을 연다 시작프로그램 >> 실행 >> cmd
C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0\bin
요기로 가서
copylocale.exe 원본locale 복사locale 이렇게 적는다
나는 copylocale.exe en_US en_KR 을 했다
이렇게 실행이 된다
다시
C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0\frameworks\locale
로 가보면 en_US, en_KR, ja_JP 가 있다
en_KR 폴더에 가면
automation_agent_rb.swc, datavisualization_rb.swc
파일만 없고 나머지 파일은 있는것을 확인할 수 있다 (저 위에 있는것은 bulider 정식 버전에서 쓰이나 차트나, AdvancedDataGrid등 이런것들이다..)
이제 빌더로 가보자~!
flex 에서 application.mxml 이 있는 경로에 locale 이란 폴더를 만들어 준다
그리고 언어 변환을 할 en_US,en_KR 두개의 폴더를 locale 폴더 안에 만들어준다
그리고 properties 파일을 만들어 준다
properties 파일은 java에서 HashMap,HashTable 과 같이 key = value 로 들어가는 프로퍼티들을 모은 파일이다 flex에서 따지자면 Object같은? Object도 Object.key = value; 로 할수 있으니까..
나는 jang.properties 파일을 만들것이다 (각각 en_US, en_KR 폴더에 하나씩 만들어 준다)
이제 properties 파일을 열고 KEY = VALUE를 넣어준다
이런구조?
여기서 주의해야 할점... properties 파일은 이클립스에서 기본적으로 만들때 파일 encoding이
ISO-8859-1 이다 저장을 할려면 안될것이다..그러므로 UTF-8로 변환을 해주어야 한다
(각 파일마다 전부 UTF-8로 변환을 해주었다면 알아서 UTF-8로 변환 해주니까 상관없음...
encoding 변환방법
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Metadata>
[ResourceBundle("jang")]
</mx:Metadata>
<mx:Script>
<![CDATA[
[Bindable]
private var locales:Array = [ "en_US" , "en_KR" ];
private function localeComboBox_initializeHandler(event:Event):void
{
localeComboBox.selectedIndex = locales.indexOf(resourceManager.localeChain[0]);
}
private function localeComboBox_changeHandler(event:Event):void
{
resourceManager.localeChain = [ localeComboBox.selectedItem ];
}
]]>
</mx:Script>
<mx:Label text="{resourceManager.getString('jang', 'NAME')}"/>
<mx:ComboBox id="localeComboBox" dataProvider="{locales}"
change="localeComboBox_changeHandler(event)"/>
</mx:Application>
Localization.mxml 파일을 이렇게 고친후
Flex 컴파일에서 설정 하자~!
Project >>마우스 오른쪽 클릭 >> Properties
를 클릭후
Flex Compiler >> Additional compiler arguments 로 간다
그리고 -locale en_US en_KR -source-path=locale/{locale}이렇게 넣어 준다
OK 누른후 Localization.mxml 실행
피드 구독하기:
글 (Atom)