337 18 Adobe Flash CS4 Professional MovieClip ActionScript Flash ActionScript Flash Flash Flash MovieClip MovieClip ActionScript ( ) MovieClip Flash Sprite ActionScript MovieClip ActionScript 3.0 Shape Sprite MovieClip 240 DisplayObject ActionScript ActionScript ActionScript SWF Flash Player ActionScript AVM1 SWF ActionScript 1.0 ActionScript 2.0 SWF Flash Player 8 AVM2 SWF ActionScript 3.0 SWF Adobe Flash Player 9 Adobe AIR SWF SWF SWF SWF SWF
338 MovieClip Flash ( ) ActionScript Flash Player AIR 1 Flash 2 3 Script 4 > 5 mymovieclip mymovieclip 6 > 29 MovieClip SWF Flash MovieClip ActionScript SWF Flash MovieClip childclip parentclip parentclip.childclip.play(); Flash Event.ADDED_TO_STAGE ActionScript 2.0 MovieClip _width _height width height _xscale _yscale scalex scaley MovieClip ActionScript 3.0
339 Flash MovieClip MovieClip ActionScript Flash MovieClip SWF ActionScript Stage.frameRate play() stop() bicycle bicycle.stop(); ( ) startbutton // This function will be called when the button is clicked. It causes the // bicycle animation to play. function playanimation(event:mouseevent):void bicycle.play(); // Register the function as a listener with the button. startbutton.addeventlistener(mouseevent.click, playanimation); play() stop() nextframe() prevframe() enterframe play() nextframe() enterframe bicycle bicycle // This function is called when the enterframe event is triggered, meaning // it's called once per frame. function everyframe(event:event):void if (bicycle.currentframe == 1) bicycle.gotoandstop(bicycle.totalframes); else bicycle.prevframe(); bicycle.addeventlistener(event.enter_frame, everyframe); 1 prevframe() nextframe() ( 1 prevframe() ) if
340 gotoandplay() gotoandstop() ( ) ActionScript ( ) ActionScript ActionScript 3.0 FrameLabel ( ) name frame FrameLabel MovieClip FrameLabel currentlabels FrameLabel currentlabel robot currentlabel robot if (robot.currentlabel == "walking") // do something Flash SWF gotoandplay() gotoandstop() FLA Flash MovieClip scenes Scene SWF currentscene Scene Scene labels FrameLabel name numframes int ActionScript MovieClip Flash ActionScript ActionScript 3.0 API MovieClip MovieClip
341 ActionScript 3.0 ( ) addchild() addchildat() 231 ActionScript Flash ( ActionScript ) ActionScript SWF ActionScript ActionScript ActionScript 1 2 3 ActionScript ( Tree House TreeHouse ) ActionScript flash.display.movieclip Sprite ( MovieClip) 4 Flash ActionScript ( ) SWF MovieClip Flash package import flash.display.movieclip; public class ExampleMovieClip extends MovieClip public function ExampleMovieClip() ActionScript 50 ActionScript Circle Circle.as MovieClip getarea() getcircumference()
342 package import flash.display.movieclip; public class Circle extends MovieClip public function Circle() public function getarea():number // The formula is Pi times the radius squared. return Math.PI * Math.pow((width / 2), 2); public function getcircumference():number // The formula is Pi times the diameter. return Math.PI * width; ( Flash 1 ) var c:circle = new Circle(); addchild(c); trace(c.width); trace(c.height); trace(c.getarea()); trace(c.getcircumference()); ActionScript Circle ActionScript Circle Flash Circle 1
343 import flash.geom.colortransform; var totalcircles:uint = 10; var i:uint; for (i = 0; i < totalcircles; i++) // Create a new Circle instance. var c:circle = new Circle(); // Place the new Circle at an x coordinate that will space the circles // evenly across the Stage. c.x = (stage.stagewidth / totalcircles) * i; // Place the Circle instance at the vertical center of the Stage. c.y = stage.stageheight / 2; // Change the Circle instance to a random color c.transform.colortransform = getrandomcolor(); // Add the Circle instance to the current timeline. addchild(c); function getrandomcolor():colortransform // Generate random values for the red, green, and blue color channels. var red:number = (Math.random() * 512) - 255; var green:number = (Math.random() * 512) - 255; var blue:number = (Math.random() * 512) - 255; // Create and return a ColorTransform object with the random colors. return new ColorTransform(1, 1, 1, 1, red, green, blue, 0); transform (Circle MovieClip ) SWF ActionScript 3.0 SWF Loader SWF ActionScript 1 URL URLRequest 2 Loader 3 Loader load() URLRequest 4 ( Flash ) addchild() Loader var request:urlrequest = new URLRequest("http://www.[yourdomain].com/externalSwf.swf"); var loader:loader = new Loader() loader.load(request); addchild(loader); URL ( SWF URL) JPEG GIF PNG SWF ActionScript SWF Flash Player AIR SWF ActionScript SWF SWF SWF SWF SWF SWF SWF 548 ApplicationDomain 600 SWF
344 SWF Loader.content SWF ActionScript 3.0 Sprite SWF SWF ActionScript AVM2 (ActionScript Virtual Machine 2) ActionScript 3.0 SWF ActionScript 1.0 2.0 SWF AVM1 (ActionScript Virtual Machine 1) AVM1 SWF (Loader.content ) AVM1Movie AVM1Movie MovieClip AVM2 SWF AVM1Movie AVM2 SWF AVM1 SWF ActionScript 3.0 AVM1Movie RuntimeAssetsExplorer ActionScript Flash Player AIR SWF ActionScript SWF Flash SWF SWF SWF RuntimeAssetsExplorer RuntimeAsset SWF SWF Loader.load() SWF ActionScript MovieClip ActionScript Flash Player SWF 590 www.adobe.com/go/learn_programmingas3samples_flash_tw Samples/RuntimeAssetsExplorer RuntimeAssetsExplorer RuntimeAssetsExample.mxml Flash FLA Flex MXML RuntimeAssetsExample.fla RuntimeAssetsExample.as GeometricAssets.as Flash (FLA) RuntimeAsset GeometricAssets.fla GeometricAssets (FLA ) FLA ActionScript
345 com/example/programmingas3/runtimeassetexplorer/runtimelibrary.as com/example/programmingas3/runtimeassetexplorer/animatingbox.as com/example/programmingas3/runtimeassetexplorer/animatingstar.as Explorer SWF Explorer SWF Explorer SWF 87 RuntimeLibrary getassets() package com.example.programmingas3.runtimeassetexplorer public interface RuntimeLibrary function getassets():array; SWF RuntimeLibrary SWF SWF SWF SWF SWF RuntimeLibrary GeometricAssets RuntimeLibrary FLA RuntimeLibrary getassets() package import flash.display.sprite; import com.example.programmingas3.runtimeassetexplorer.runtimelibrary; public class GeometricAssets extends Sprite implements RuntimeLibrary public function GeometricAssets() public function getassets():array return [ "com.example.programmingas3.runtimeassetexplorer.animatingbox", "com.example.programmingas3.runtimeassetexplorer.animatingstar" ];
346 getassets() ( AnimationAssets) FLA MovieClip MovieClip AnimatingStar AnimatingBox package com.example.programmingas3.runtimeassetexplorer import flash.display.movieclip; public class AnimatingStar extends MovieClip public function AnimatingStar() FLA GeometricAssets MovieClip 360 animatingbox animatingstar ActionScript getassets() MovieClip flash.display.movieclip FLA SWF AVM2 SWF SWF AnimatingBox AnimatingStar SWF ASSETS_PATH FileReference SWF Flash Player runtimeassetsloadcomplete() private function runtimeassetsloadcomplete(event:event):void var rl:* = event.target.content; var assetlist:array = rl.getassets(); populatedropdown(assetlist); stage.framerate = 60; rl SWF SWF getassets() populatedropdown() ComboBox addasset() private function addasset():void var classname:string = assetnamecbo.selecteditem.data; var AssetClass:Class = getdefinitionbyname(classname) as Class; var mc:movieclip = new AssetClass();... ComboBox (assetnamecbo.selecteditem.data) getdefinitionbyname() ( flash.utils )