In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ScrollRectのテスト 2010-2-17

Get Adobe Flash player
by Makoto_Tanaka 17 Feb 2010
/**
 * Copyright Makoto_Tanaka ( http://wonderfl.net/user/Makoto_Tanaka )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7CG9
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    
    import flash.geom.Rectangle;
    import flash.events.Event;
    public class FlashTest extends Sprite {
    		private var _text1:TextField;
    		private var _text2:TextField;
    		
        public function FlashTest() {
        	
        		var t:TextField = new TextField();
        		t.text = "scrollRect無し";
        		t.x = 100;
        		t.y = 35;
        		this.addChild(t);
        		
            _text1 = new TextField();
            _text1.text = "Hello World";
            
            var sprite:Sprite = new Sprite();
            sprite.graphics.beginFill(0xff0000, 0.2);
            sprite.graphics.drawRect(0,0,100,16);
            sprite.graphics.endFill();
            sprite.x = 100;
            sprite.y = 50;
            sprite.addChild(_text1);
            addChild(sprite);
            
            t = new TextField();
        		t.text = "scrollRect有り";
        		t.x = 100;
        		t.y = 85;
        		this.addChild(t);
        		
            _text2 = new TextField();
            _text2.text = "Hello World";
            
            sprite = new Sprite();
            sprite.graphics.beginFill(0x00ff00, 0.2);
            sprite.graphics.drawRect(0,0,100,16);
            sprite.graphics.endFill();
            sprite.x = 100;
            sprite.y = 100;
            sprite.addChild(_text2);
            addChild(sprite);
            
            // scrollRectを設定して表示できる範囲を指定する
            sprite.scrollRect = new Rectangle(0,0,100,16);
            
            this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(e:Event):void {
        		_text1.x--;
        		_text2.x--;
        		
        		if (_text1.x < -_text1.textWidth) {
        			_text1.x = 100;
        			_text2.x = 100;
        		}
        }
    }
}