BLOG main image
Category (342)
MySpace (89)
Astronomy (50)
Development (178)
Drum (25)
linux에서 subversion설정
누리에 없을 자그마한 자국
살라딘의 생각
saladin's me2DAY
3D Avata - BuddyPoke
기찬 개발이야기
[FLEX] ANT로 ASDOC 사용하기
THLIFE.net
Flash10 대응 Textcube 1.7.5.1..
텍스트큐브 공지사항
«   2008년 11월   »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
325662 Visitors up to today!
Today 162 hit, Yesterday 963 hit
/Development/Flex/AIR 관련글 보기 2007년 08월 02일 20시 41분


좌측 Panel을 마우스로 클릭해보길 바란다.
이 프로그램은 State와 Transition을 활용한 것이다.
아주 간단하게 구현했음에도 불구하고 이런 효과를 내는 Flex가 참 멋지다는 생각이 든다.

State는 화면을 전환하기 위한 것이다.
Transition은 화면 전환시 이펙트를 주는 것이다.

나는 Adobe LiveDocs에서 제공한 MXML 코드를 ActionScript로 변환해 보았다.

MXML을 ActionScript로 만들어보는 연습이 필요한 이유는 다음과 같다.
  1. Flex의 구조를 이해할 수 있다. 
    MXML은 디자인뷰에서 사용하기 편하고 적은양의 코드에서는 상당히 직관적이긴 하다. 하지만 MXML도 실제로 보면 ActionScript로 모두 구현할 수 있는 것이다. 이러한 연습은 알게 모르게 Flex 전체를 공부하는데 큰 도움을 준다.
  2. 동적 Component 제작 능력을 키워준다.
      MXML은 동적으로 Component를 만들기 힘들다. 하지만 ActionScript를 이용하면 동적 Component생성이 자유롭다. 가령 위와 같은 Panel이 3개가 아닌 그 이상의 Panel이 동적으로 생성되어야 한다고 해보자. MXML로는 제작이 거의 불가능할 것이다.


MXML 소스파일 (
Transition과 States MXML 예제 (Language : xml)
<?xml version="1.0" ?>
<!-- transitions/DefiningTrans.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" >
    <!-- http://flexdocs.kr/docs/flex2/docs/00000938.html -->
    <!-- Define the two view states, in addition to the base state.-->
    <mx:states>
        <mx:State name="One">
            <mx:SetProperty target="{p1}" name="x" value="110"/>
            <mx:SetProperty target="{p1}" name="y" value="0"/>
            <mx:SetProperty target="{p1}" name="width" value="200"/>
            <mx:SetProperty target="{p1}" name="height" value="210"/>
            <mx:SetProperty target="{p2}" name="x" value="0"/>
            <mx:SetProperty target="{p2}" name="y" value="0"/>
            <mx:SetProperty target="{p2}" name="width" value="100"/>
            <mx:SetProperty target="{p2}" name="height" value="100"/>
            <mx:SetProperty target="{p3}" name="x" value="0"/>
            <mx:SetProperty target="{p3}" name="y" value="110"/>
            <mx:SetProperty target="{p3}" name="width" value="100"/>
            <mx:SetProperty target="{p3}" name="height" value="100"/>
        </mx:State>
        <mx:State name="Two">
            <mx:SetProperty target="{p2}" name="x" value="110"/>
            <mx:SetProperty target="{p2}" name="y" value="0"/>
            <mx:SetProperty target="{p2}" name="width" value="200"/>
            <mx:SetProperty target="{p2}" name="height" value="210"/>
            <mx:SetProperty target="{p3}" name="x" value="0"/>
            <mx:SetProperty target="{p3}" name="y" value="110"/>
            <mx:SetProperty target="{p3}" name="width" value="100"/>
            <mx:SetProperty target="{p3}" name="height" value="100"/>
        </mx:State>
    </mx:states>

    <!-- Define Transition array with one Transition object.-->
    <mx:transitions>
        <!-- Define a transition for changing from any state to any state.
        -->

        <mx:Transition id="myTransition" fromState="*" toState="*">
            <!-- Define a Parallel effect as the top-level effect.-->
            <mx:Parallel id="t1" targets="{[p1,p2,p3]}">
                <!-- Define a Move and Resize effect.-->
                <mx:Move  duration="400"/>
                <mx:Resize duration="400"/>
            </mx:Parallel>
        </mx:Transition>
    </mx:transitions>

    <!-- Define the Canvas container holdig the three Panel containers.-->
    <mx:Canvas id="pm" width="100%" height="100%" >
        <mx:Panel id="p1" title="One"
                x="0" y="0" width="100" height="100"
                click="currentState='One'" >

            <mx:Label fontSize="24" text="One"/>
        </mx:Panel>
       
        <mx:Panel id="p2" title="Two"
                x="0" y="110" width="100" height="100"
                click="currentState='Two'" >

            <mx:Label fontSize="24" text="Two"/>
        </mx:Panel>
       
        <mx:Panel id="p3" title="Three"
                x="110" y="0" width="200" height="210"
                click="currentState=''" >

            <mx:Label fontSize="24" text="Three"/>
        </mx:Panel>
    </mx:Canvas>
</mx:Application>

 

위 MXML 코드를 ActionScript 로 바꿔본 소스

TransitionTest.mxml (Language : xml)
<?xml version="1.0" ?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" xmlns:my="*" >
    <my:TestUI width="100%" height="100%"/>
</mx:Application>

 


TestUI.as (Language : java)
package {
    import mx.core.UIComponent;
    import flash.events.MouseEvent;
    import mx.containers.Panel;
    import mx.controls.Label;
    import mx.events.FlexEvent;
    import mx.states.State;
    import mx.states.Transition;
    import mx.states.SetProperty;
    import mx.effects.Parallel;
    import mx.effects.Move;
    import mx.effects.Resize;
    import mx.effects.Effect;
   
    public class TestUI extends UIComponent
    {
        public function TestUI()
        {
            super();
            this.addEventListener( FlexEvent.CREATION_COMPLETE, onCreationComplete );
        }
       
        private function onCreationComplete( e:FlexEvent ):void
        {
            var p1:Panel;
            var p2:Panel;
            var p3:Panel;
            var label:Label;
            var sp:SetProperty;
            var parallel:Parallel;
            var moveEffect:Move;
            var resizeEffect:Resize;
            var transition:Transition;
           
            //Panel 1
            p1 = new Panel();
            p1.name = "One";
            p1.title = "one";
            p1.x = 0;
            p1.y = 0;
            p1.width = 100;
            p1.height = 100;
            p1.addEventListener( MouseEvent.CLICK, onMouseClick );
            label = new Label;
            label.setStyle( "fontSize", "24" );
            label.text = "One";
            p1.addChild( label );
            this.addChild( p1 );
           
            //Panel 2
            p2 = new Panel();
            p2.name = "Two";
            p2.title = "two";
            p2.x = 0;
            p2.y = 110;
            p2.width = 100;
            p2.height = 100;
            p2.addEventListener( MouseEvent.CLICK, onMouseClick );
            label = new Label;
            label.setStyle( "fontSize", "24" );
            label.text = "Two";
            p2.addChild( label );
            this.addChild( p2 );

            //Panel 3
            p3 = new Panel();
            p3.name = "";
            p3.title = "Three";
            p3.x = 110;
            p3.y = 0;
            p3.width = 200;
            p3.height = 210;
            p3.addEventListener( MouseEvent.CLICK, onMouseClick );
            label = new Label;
            label.setStyle( "fontSize", "24" );
            label.text = "Three";
            p3.addChild( label );
            this.addChild( p3 );

            //State 1
            var state:State;
            var properties:Array;
            var property:Array;
           
            state = new State();
            state.name = "One";
            properties = [  [ p1, "x",     110   ],
                            [ p1, "y",   0    ],
                            [ p1, "width",  200  ],
                            [ p1, "height", 210  ],
                            [ p2, "x",    0 ],
                            [ p2, "y",    0 ],
                            [ p2, "width"100   ],
                            [ p2, "height", 100  ],
                            [ p3, "x",    0 ],
                            [ p3, "y",    110   ],
                            [ p3, "width"100   ],
                            [ p3, "height", 100 ],
                        ];
            for each ( property in properties )
            {
                sp = new SetProperty( property[0], property[1], property[2] );
                state.overrides.push( sp );
            }
            this.states.push( state );
           
            //State 2
            state = new State();
            state.name = "Two";
            properties = [
                            [ p2, "x",    110   ],
                            [ p2, "y",    0 ],
                            [ p2, "width"200   ],
                            [ p2, "height", 210  ],
                            [ p3, "x",    0 ],
                            [ p3, "y",    110   ],
                            [ p3, "width"100   ],
                            [ p3, "height", 100 ],
                        ];
            for each ( property in properties )
            {
                sp = new SetProperty( property[0], property[1], property[2] );
                state.overrides.push( sp );
            }
            this.states.push( state );

            //transition 설정
            transition = new Transition;
            transition.fromState = "*";
            transition.toState = "*";

            parallel = new Parallel();
            parallel.targets.push( p1, p2, p3 );
           
            moveEffect = new Move();
            moveEffect.duration = 400;
            parallel.addChild( moveEffect );

            resizeEffect = new Resize();
            resizeEffect.duration = 400;
            parallel.addChild( resizeEffect );
           
            transition.effect = parallel as Effect;
            this.transitions.push( transition );
        }
       
       
        private function onMouseClick( e:MouseEvent ):void
        {
            var p:Panel = e.currentTarget as Panel;
            if( null != p )
            {
                this.currentState = p.name;
            }
        }
    }
}
 



참고사이트
States 사용 : http://flexdocs.kr/docs/flex2/docs/00000923.html
Transtion 사용 : http://flexdocs.kr/docs/flex2/docs/00000938.html
ViewState와 Transition 사용 : http://flexdocs.kr/docs/flex2/docs/00000098.html
View States와 트랜지션의 추가  :http://flexdocs.kr/docs/flex2/docs/00000309.html 

글쓴이 : 지돌스타 ( http://blog.jidolstar.com/178 )
이 글의 관련글
Trackback Address :: http://blog.jidolstar.com/trackback/178
BlogIcon 지돌스타 | 2007년 08월 02일 20시 42분 | PERMALINK | EDIT/DEL | REPLY
Name
Password
Homepage
Secret