This week, the children of the 4 grade began to learn equations and used algebra. To make it easier for the child to understand and to apply it, he intends to teach him a little programming.
The choice of the program can not be too difficult, such as Java, C # should not, learning JavaScript should be OK, but will be more boring, so decided to let him play flash. Although Flash is declining with the rise of HTML5, Flash is easy to understand and can help children draw.
This program chose the process of the snow flower, although simple, but the content is still relatively full, involving: Hand animation video clips (MC), frames, ActionScript, variables, random functions, function methods, events, time and so on. Steps:
1, FLASH CS6, new "ActionScript 3", black background.
2. Insert the new symbol (shortcut: Ctrl + F8) and select "for ActionScript" to export to make this component a class. such as the class name, we can play a: snow. Just use a pencil tool to draw a "M" Glyph on the line, slightly thicker, and use the Zoom tool to narrow it down. The color naturally needs to be white slightly.
3. In the first frame, add the background (I did not add). Then add another layer, press F9, pop up the programming box (AS3 requires programming cannot share a layer with other layers). The contents are as follows (including explanations):
Import Flash.utils.Timer; The preceding 2 slash is the meaning of the note, which means that the content will not be recognized by the computer later. And this line does not need to write, because in writing the back of the timer, the system will automatically write for (var i:int=0; i<230; i++) {//loop notation, indicating the loop 230 times, each increase of 1 Var mc:movieclip=new snow (); Variables start with var. Snow is the class of MC that we have defined earlier. Because the Loop 230 times, this line means that each cycle should be born out of an identical snowflake AddChild (MC); To appear in the movie, you need to add it with this addchild. Mc.x=math.random () *stage.stagewidth; Math.random () indicates that a decimal between 0 and 1 is randomly generated, and stage.stagewidth is a built-in property that represents the width of this movie. So we are positioning the snowflakes each time the x-coordinate position, and not greater than the total width of the movie. Mc.y=math.random () *stage.stageheight; The y-coordinate that appears. The x/y coordinates are counted from the upper left corner. Mc.scalex=mc.scaley=math.random () *0.8+0.2; Scale, which means that the minimum is 0.2 times times the original and 1 time times the maximum. Mc.alpha=math.random () *0.6+0.4; The minimum transparency is 40% and the maximum is 100%. Mc.vx=math.random () *2-1; The above parameters will appear automatically after clicking, but this VX and the following VY will not appear, this is custom, you can write the other casually. Represents the X/Y offset of each drop. Mc.vy=math.random () *3+3; Mc.name= "MC" +I; To make a name for each snowflake, the following procedure is easy to find. }//addeventlistener (EVENT.ENTER_FRAME,SNOWP); Originally this line, Flash is about 24 frames per second, that is, every 1/24 seconds to execute this function called SNOWP. AddEventListener (MOUSEEVENT.MOUSE_OVER,SNOWP); As with the upstream, these are the methods that the event adds. var timer1:timer=new TImer (50); To precisely control the time interval, use this to indicate that no 50 milliseconds are executed. Timer1.addeventlistener (TIMEREVENT.TIMER,SNOWP); This adds time to the function before the instantiation of the timer1 is used. The event name can be selected from the left of the programming box. Timer1.start (); Start//function snowp (evt:event): void {//This line is the function snowp corresponding to Event.enter_frame (evt:timerevent): void {// and Timerevent.timer corresponds for (var i:int=0; i<230; i++) {var mc:movieclip=getchildbyname ("MC" +i) as MovieClip;//Root According to the snowflake name defined above to find the already instantiated movie, as is the meaning of. When you write get, you can click "Show Code Hints", you can display the following content, good for people with bad brain. MC.X+=MC.VX; Offset a little bit at a time, below is a little down. Mc.y+=mc.vy; if (mc.y>stage.stageheight) {//If snowflakes fall to the bottom of the movie, start from the top. mc.y=0; } if (mc.x<0| | Mc.x>stage.stagewidth) {//float to the left and right, then random horizontal axis appears. Mc.x=math.random () *stage.stagewidth; } }}
It's done, you can try it.
To the above this film, you can make them all into a MC, so that the big film, you can nest this small film, small films in small films, the big environment to play the big environment.
The blog editor of this site is really unable to say that the system always appear a lot of garbled characters, such as:
The time that led me to typesetting was longer than the time I wrote the article!
ACTIONSCRIPT3 Write the Snowflake program, for the training of children programming interest