Flash Practical Code Summary 1th/2 page _flash as

Source: Internet
Author: User
Tags add time goto
External call SWF
On (release) {
Loadmovienum ("service.swf", 1);
}
External Call data
Loadvariablesnum ("About.txt", 0);
System.usecodepage = true;//Chinese
Music Join
Mysound = new Sound ();
Mysound.attachsound ("1");
Mysound.start ();
Turn off the specified music
Mysound.stop ("1");
External calling Music
Mysound=new Sound ();
Mysound.loadsound ("Music.mp3", true);
Mysound.start (0,100)
Turn off music
Mysound.stop ();
Link scene:
On (release) {
gotoAndStop ("History of the Cat", 1);
}
External call
On (release) {
Loadmovienum ("a.swf", 1)
}
Empty text box
_root.text= ""
On (release)
Set Variable: "Input" = ""
Set Variable: "Output" = ""
End on
Easy to realize flash full screen playback
Many people have seen this effect: the CD into the optical drive, the CD automatically run, and then a flash system
For the opening animation, the animation is full screen playback, and right click Invalid, after the animation playback ended, appear "off" press
button, and when clicked, the full screen animation closes.
In fact, the above mentioned Full-screen playback and the cancellation of the right menu and other effects are dependent on the Fscommand instructions to play a role.
The Fscommand directive is used primarily to control the Flash movie player, but it can also be used to open other applications.
The Fscommand directive is valid only if the Flash movie player executes (. swf and. exe) during the flash production process
, you can preview the animation as "Ctrl+enter", and when you publish the animation as a Web page file, this directive does not perform its function

The syntax used by the Fscommand Directive is: Fscommand ("command", "arguments") 
The command is an instruction-related order, arguments is the parameter of the command.
Now let's talk about how to use the Fscommand instructions to achieve full screen playback, flash playback when the right button
Menu and turn off Flash animations.
1, full screen play flash
"Fullscreen" is meant to be full screen and, by default, Flash animations are not played in full screen (false
If you need to have the animation play in Full-screen state, you must set the fullscreen command to True, written as:
Fscommand ("fullscreen", "True");
As needed, we can write it to frames, buttons, MC (Movie Clip).
2, Cancel the right button menu
The ShowMenu command is used to set the shortcut menu that is (True) No (false) to display the Flash animation player.
All instructions, that is, right click the Mouse pop-up menu, the default is true, if you want to cancel pop-up menu, must be in the first
Frame This setting:
Fscommand ("ShowMenu", "false");
3, turn off the animation
The QUIT command is a. swf and. exe file that is used to close the player, which has no arguments, written as:
Fscommand ("Quit");
If you want a button that closes the animation at the end of the Flash animation, you can do so by following these steps.
Execute "New Symbol" under "Insert" (or press Ctrl+f8), select the button in the pop-up window, and
After making a simple button, back to the scene, select the last frame, from the "Library" in the button just created
Drag into the scene because the button appears at the end of the animation.
Write the following code to the button, the implementation of the press button to turn off Flash animation.
On (release)
{
Fscommand ("Quit"); 
}
One or several action commands
1. To play and stop a movie:
Play () ()//player Command Stop ()/Stop command
2. Change the Frame Flow command
gotoAndPlay (frame)//jumps to the specified screen and plays continuously.
gotoAndStop (frame)//jumps to the specified screen and stops playing.
Gotandplay ("Scene name", frame)//jumps to the specified scene frame and plays continuously.
gotoAndStop ("Scene name:, Frlme)//jumps to the specified scene frame and stops playing."
NextFrame ();///skip to Next frame playback;
Prevprame ();//skip to Previous frame play.
3. To control the playback and stopping of movie clips: Telltarget command
such as: Telltarget ("C1")
{gotoAndStop (2);}//skips the 2nd frame of the movie clip instance C1 and stops.
Two, the production method of several functional components
1. The making of a timer
Click menu Insert/new Symbol, enter the caret name (such as a timer) in the pop-up dialog box, and
Select the Type tool, the property is dynamic text, and draw two text boxes in the first frame. Set the change separately
Munite and timer, draw a colon-like dot between two text boxes (these two dots can be made into a
The symbol, the type is the movie fragment, flashes once per second. And then drag it between the two text boxes. Inserts a frame in the second frame. In
The first frame Input action script (action) is as follows:
Set the initial value of the time
if (!started) {
Start_time=gettimer ();
Started=true;
timer=0;
I=o;
munite=0;
}
X=gettimer ()-start_time;//Calculation time change
X=int (x/1000);//The Unit of time is 1000 nanoseconds.
Y=x-60*i
if (y>59)
{i=i+1;munite=munite+1
Timer=timer+1:
}
Else
{Timer=y}
After the symbol is finished. Drag it into the main scene.
2. The Intelligent Judgment quick choice question, and makes the correct and correct prompt
Click the menu insert/new symbo1 and enter the name of the caret in the dialog box that pops up. such as: "To the wrong prompt."
The symbol type is "movie fragment." In the first frame input text "Enter the answer in parentheses, press Enrer key to determine" in
Enter the action script on the frame:
_root.flah=false;_root.ans= ""; gotoAndStop (1); Insert an empty keyframe at frame 16th. On the frame
Draw a figure like "X" or input text "x", insert Keyframe in frame 30th, frame aaction as _root.ans= "
": gotoAndStop (31); Insert a blank keyframe in frame 31st, and the static text is lost on the frame" please redo, press E
Nter key OK. "Enter script in this frame:" Stop (); "At this point, the symbol is made master or: for example:
Question 1th: 20 ()
A 2 B. 3 C. 4 D. 0
Inserts a dynamic text box at the top bracket position, without entering any content. The text box variable is named: Ans. In the frame appropriate
Position Insert Movie "Right to Wrong hint", the movie Fragment Name property is "QL", the movie Fragment on the script:
Keyboard Event Control Program
Onclipevent (KeyDown)
}
Gets the key value of the key
Keycode=key.getcode ();
Determine if the ENTER key
if (Keycode==key. ENTER) {
Determine if the correct answer is entered
Answer=number (A)
if (_root,ans== "a" or _root.ans== "a" {
Show "correct" information
Telltsrget (_ROOT.Q1) {
gotoAndPlay (2);
}
} else {
Show "wrong Answer" message
Telltarget (_ROOT.Q1) {
gotoAndPlay (16)
}
}
}
}
3. The load and control of sound
Insert a piece of music: in the Pile/import to library, find the music you want to insert (for example, Steed Pentium), open
Library, find the "Steed Pentium" symbol, right-click, click Linkage in the pop-up menu ... command, and then in the pop-up
menu, select the Export for ACTIONSC option and enter an identifier in the Indentify box: such as music.
Insert the following script in the frame you want to play:
Soun=new Sound ()//Create sound instance
Sound.attachsound ("Music");
Sound.start (0,2)/play Music 2 times
Sound.setvolume (70): The volume of the music is 70%.
The above load music is loaded through frames, or it can be loaded by a button.
The way to stop music: Make a button and lose a script on the button:
On (release)
{
Sound.stop ();
}
4. How to use the keyboard to control the jump of a frame
Some teachers like to use the keyboard to operate, how to make this kind of operator freely? The following methods are produced with Flash MX:
Make a symbol (such as "Knowledge Review"), the symbol type is "movie fragment". In this symbol you will need to review the
Knowledge point by frame display, each frame action script is: Stop () back to the main scene, in the required frame insert the symbol, the frame foot
This is: Stop (), after inserting. Click the symbol. To lose a person script:
Onclipevent (key down) {//keyboard response, press the Next button should be ordered
NextFrame ();
}
This enables you to jump to a specified frame by pressing any key. This example is only a basic method, reader friend in
You can have more extensions when you apply.
5. The mouse points to show the answer to the blank question
Show some answers to questions that can be made with this answer-a button in which the up frame can be blank key
Frames, and other frames are the answer content. In the answer to the question, insert the button in the frame to enter the script:
On (release) {
gotoandstop;//frame I fixed the answer on the screen
A method of realizing the jump between flash scenes
Author: anon Source: InterNet Add Time: 2005-2-25
In the production of Flash animation, there may be a very big MC
Sometimes you put it in a few scenes, so how does a jump in a scene come true?
1.
Method One: (Use Telltarg ...
Method One: (using the Telltarget command)
The As on the button is:
On (release) {
Telltarget ("/") {
gotoAndPlay ("Scene 1", 1);
}
}
2.
Method Two (with Gotoandpla ...)
Method two (with gotoandplay command)
The MC in main scene 2 is placed on the timeline of scene 2
Button as:
On release {
gotoAndPlay ("Scene 1", 1)
}
and add a stop () to the last frame
The problem will be solved:
3.
Method three (using the path _root.g ...
Method three (using the path _root.gotoandplay ())
In the second scene 2 there is only one MC, at the last frame of this MC is the stop and a replay press
Button
As:_root.gotoandplay of buttons (1)
"That tells the button to return to the first frame of scene 1."
4.
Method Four (give a different name to the scene) ...
Method Four (give a different name to the scene)
If you write as this:
There is only one MC in the second sence, the last frame of this MC is stop and a repl
Ay button
Button as:
On release {
gotoAndPlay ("Sence1", 1)

The result is that it starts playing from the first frame of the MC, not from the first frame of the Sence1.
This is because the name of the main scene defaults to Sencen
MC can also have multiple scenes, and the MC is the default for Sencen
So when you use gotoAndPlay ("Scene1", 1) on the MC, it refers to the first frame in the MC in the scene where the
Not the main scene.
The solution is to define different names for the scene
Scene1 Our name is: Main scene
Scene2 Our name is: Sub Scene 1
The correct as should be:
On (release) {
Telltarget (_root) {
gotoAndPlay (1);
}
}
If you want to implement the button click to play from the second scene can be written on the button:
On (release) {
Telltarget (_root. Second scene) {
gotoAndPlay (1);
}
}
5.
Method five (using label labels) ...
Method five (using label labels)
We don't usually play from the beginning when we control the animation, maybe we want to start from a key frame of a scene.
Start playing, then the label is
The best way to achieve it;
For example, when we want to click on the button above to let the animation from the main scene of the Label1 start playing, then the button on the
As should be:
On (release) {
Telltarget (_root) {
gotoAndPlay ("Label1");
}
For example, there are 3 scenes where we want to play the animation from the Label4 in the second scene 1 when we click on the button above.
Then the as on the button should be:
On (release) {
Telltarget (_root) {
gotoAndPlay ("Sub Scene 1", "label4");
}
}
}
}
If you want to implement the button click to play from the second scene
You can write on the button:
On (release) {
Telltarget (_root. Second scene) {
gotoAndPlay (1);
}
}
3, what is the vector map?
Vector graphics can be arbitrarily scaled without affecting the quality of flash, bitmap images generally only as static elements or background map, Fla
SH is not good at processing bitmap image action, should avoid the animation of bitmap image elements.
4, how to quickly align objects in different frame?
Enter coordinates directly with the Inspector "Ctrl+alt+i".
or toolbar 〉〉 window 〉〉 panel 〉〉 Arrange "Ctrl+k" to bring up the arrangement panel. Legend
5, how to adjust the transparency of a SYMBOL/MC?
Select SYMBOL/MC, and the menu bar finds modify (modified) 〉〉instance (instance) 〉〉color effect (effect
) 〉〉alpha (transparency) adjustment is OK.
6, do a good job in the Flash after the HTML, it is always looping, how can it not to cycle?
The last action is set to stop (stop)
7, how to give my flash to do a preload loading?
Implemented with action syntax if frame is loaded, create a new layer, this layer is dedicated to action,
First frame,
ifframeloaded ("Scene", frame)//If the number of frames in the scene has been loaded
Goto and Play ()//jumps to and plays XXX (own set)
{}
Second frame,
Goto and Play ("Scene 1", 1)//jumps to and plays the first loop
Add a load to the MC Loop played in the middle of the two frames, OK.
What, you want to loading in great detail? Then as the source, enough detail.
SOURCE download
8, how to click a button to open a page HTML instead of a Zhen.
Make a button that is written directly above as:
On (release)
GetURL ("***.html");
{}
Here ***.html is you want to open the page file name, of course, can also be a certain URL address, such as HTTP://WW
W.flash8.net
9, I placed a very big MC in the button, why I did not click to button the mouse became a hand-shaped
State?
button Real activation area is in the hit (press) the location, if you want to control the position of the button for a certain value, you can hit in the painting
Make a transparent figure to judge.
10. If the right mouse button is shielded? What does the FS command mean?
Fscommand ("fullscreen", "True/false"); (full screen setting, true on, false off)
Fscommand ("ShowMenu", "True/false"); (right-click menu settings, true display, False does not appear)
Fscommand ("Allowscale", "True/false"); (zoom setting, True free scaling, false adjustment screen
Does not affect the size of the movie itself)
Fscommand ("Trapallkeys", "True/false"); (shortcut key setting, True shortcut key, false shortcut key
Off
Fscommand ("exec"); (exe program call)
Fscommand ("Quit"); (exit close window)
11, the font in Flash is always very vague, with a change in the clear way?
After writing the text ctrl+t open the Text Setup Panel, and in the final text box option, select the box to use the design font.
. (Note that the best use of the song body, size 12 or 8, so more neat)
12, I want to do an MTV, how to import sound?
Very simply, ctrl+r to import your sound file on the line.
13, I make MTV voice and lyrics are always out of sync.
Ctrl+f Open the Control Panel, find the Sound tab on the right, adjust the sound to sync Effect for Strem (audio data flow) mode
Style on the line.
14, why do I make out of the MTV file is very large ah?
Refer to this post
What are the 15,flash publishing settings? How to set the transparent background?
Diagram 1 Figure 2 Figure 3
Set in Dreamewaver:
Graphic
(provided by Flashweb)
16, how can you make a beautiful font effect?
With the Third-party software swish and swfx these, flash the software resources have to download.
17, how to optimize my flash?
Refer to this post
18, I am in the Action panel Advanced mode Why is the font always small?
19, how to load a SWF file
Loadmovienum Skills
Add an open Space MC. Entity name is ok,action:
Loadmovie ("dr/test.swf", "_root.ok");
Controlling the position of this MC, the relative properties of size and so on will affect the location and size of the SWF being transferred.
SetProperty ("MC", _xscale, "* * *");
SetProperty ("MC", _yscale, "* * *");
SetProperty ("MC", _x, "* * *");
SetProperty ("MC", _y, "* * *");
SetProperty ("MC", _alpha, "* * *"); ............
20, how to import a background transparency effect of a better position map?
It is recommended that PNG format (firework) be used, and flash will support the transparency of the PNG bitmap in a fairly good way.
21. How do I use ActionScript to set the page as the homepage and to add favorites?
One, using the Geturl method:
Set as homepage:
On (release)
GetURL ("; void Document.links[0].sethomepage (' http://www.jb51.net/');", "_se
LF "," POST ");
{}
Add to Favorites:
On (release)
GetURL ("Window.external.AddFavorite" (' Http://www.jb51.net, ' cloud-dwelling community '); "," _self "," POST ");
{}
Second, with the Fscommand method, a little complicated
1, first add the code on the Flash button:
Home:
On (release)
Fscommand ("setHomePage", "http://www.jb51.net");
{}
Favorite Folders:
On (release)
Fscommand ("Addfavorite", "http://www.jb51.net| boutique material Community");
{}
Then select Flash with Fscommand in the release settings and publish to HTML
2, modify HTML:
Found it
Handle all the "Fscommand messages in a Flash movie
function sethomepage_dofscommand (command, args)
{}
This paragraph, modified into:
Handle all the "Fscommand messages in a Flash movie
function sethomepage_dofscommand (command, args)
var sethomepageobj = InternetExplorer? Sethomepage:document.sethomepage;
if (Command = = "setHomePage") {
document.links[0].style.behavior = "url (#default #homepage)";
Document.links[0].sethomepage (args);
{} else if (Command = = "Addfavorite")
args = Args.split ("|");
Window.external.AddFavorite (Args[0], args[1]);
{}
}
Finally, if there is no link in the HTML, it needs to be a. lt; SCRIPT language=javascript> The front of this sentence Tim
Add a sentence of <a href= "/" ></a>
22. How to let the animation after the end of automatic shutdown?
In the last frame of the action to select Fscommond, and then on the right to select quit, you can
23. How to introduce transparent bitmap?
A: It is a good idea to enter a PNG file. PNG is a fireworks document. Of course, you can also enter a transparent GIF in gif89a format.
Tablets
24. How to open a new custom browser window in Flash?
This problem, very common, also discussed countless times, some of the previous useful posts can not be found, and now the whole
The rationale is as follows:
A common and simple method is to use a similar
Get URL (";")
Such a sentence, but there are many problems, such as the opening of a new window, the contents of the original window is also replaced.
1. Insert the following statement in Flash where you need to open a new window action:
FS Command ("Open_window", "filename.htm;newwin;toolbar=no,location=no,status=
No
Menubar=no,scrollbars=no,resizable=no,width=320,height=200 ")
Among them arguments:
filename.htm the file name you want to open
Newwin the name of the new window
Toolbar=no,location=no,status=no,
Menubar=no,scrollbars=no,resizable=no,width=320,height=200 the properties of the new window, including dimensions
Note that the above three parts should be separated by a semicolon ";" Separated
2, in File>publish setting ... Set in
Tempalte:flash with Fscommand in HTML
Release
3, edit the publication generated HTML file, find the following paragraph:
Code:-------------------------------------------------------------------------
-------<script language=javascript>
<!--
var InternetExplorer = navigator.appName.indexOf ("Microsoft")!=-1;
Handle all the "Fscommand messages in a Flash movie
function movie1_dofscommand (command, args)
var movie1obj = InternetExplorer? Movie1:document. Movie1;
//
Place your code here ...
//
{}
...
------------------------------------------------------------------------------
--
To
Code:-------------------------------------------------------------------------
-------<script language=javascript>
<!--
var InternetExplorer = navigator.appName.indexOf ("Microsoft")!=-1;
Handle all the "Fscommand messages in a Flash movie
function movie1_dofscommand (command, args)
var movie1obj = InternetExplorer? Movie1:document. Movie1;
Place your code here ...
if (Command = = "Open_window")
{
Arg_array=args.split (";");
window.open (arg_array[0],arg_array[1],arg_array[2]);
{}
}
...
------------------------------------------------------------------------------
--
Ok!
If you are inserting an existing HTML page, you can publish it first and then copy the appropriate code to the HTML file.
25. How to use action control inverted?
Do a MC put in the right place, there are two frames
First frame:
If (GetProperty ("a", _currentframe) <=1)
Begin Tell Target ("/A")
Go to and Stop (GetProperty ("/A", _totalframes)
End Tell Target
Else
Begin Tell Target ("/A")
Go to and Stop (GetProperty ("/A", _currentframe)-1)
End Tell Target
End If
Second frame:
Go to and Play (1)
So you can let/a rewind
But there is one more problem that cannot be solved:
What if I just want to stop for a while?
For example, I added a stop at the tenth Keyframe, a stop at the 30th Keyframe, and now I want to
Stop at the stop, but there's no way to do it.
If (GetProperty ("a", _currentframe) <=1)
Begin Tell Target ("/A")
Go to and Stop (GetProperty ("/A", _totalframes)
End Tell Target
Else
Begin Tell Target ("/A")
Go to and Stop (GetProperty ("/A", _currentframe)-1)
End Tell Target
End If
Second frame:
Go to and Play (1)
This paragraph must be in an MC,
Suppose this MC is/b
In/A frame settings that need to be stopped
Begin Tell Target ("/b")
Stop
End Tell Target
Stop
It's okay.
26. What is the difference between an internal voice role and an external voice role?
No big difference.
External files can reduce file size if directed
You need to go with the DCR file when you publish or make a disc, and always keep the relative path unchanged
There's also a problem with streaming playback
If the imported sound file is too large, it will affect the synchronization effect and sound lag. (because director is playing an internal sound
Before you put it in RAM) the external sound file is streaming, playing while downloading. But pay attention to the connection road
Diameter problem.
27. How to make the sound loop endlessly?
Define the number of loops of sound to be large enough if your music is set to Strem (audio data stream) that your SWF
And the pieces will be big enough.
28. How to control the sound playback and stop
Right-click the sound file in the library, select linkage ...
Set Export this Symbol
Entifier:
Named "Sound."
And then you can set it up in stage.
s = new Sound ();
S.attachsound ("sound");
To let the sound sound off only
Perform:
S.stop ();
To get him to start playing is
S.start ();
29. How do I transfer the SWF file and control its size and position?
One, how to transfer into a SWF file:
Transfer a SWF to a layer loadmovienum ("path/moviefile.swf", 0);
Its "path/moviefile.swf" for the address to be transferred into the file, "0" for the layer number, "0" for the No. 0 layer;
Transfer a SWF to an MC
Loadmovie ("path/moviefile.swf", "Mc_name"), its "path/moviefile.swf" is to be transferred to the text
The address of the piece, "Mc_name" is the name of the MC.
Second, how to change the size of the SWF after the transfer:
SetProperty ("Mc_name", _xscale, size_x);
SetProperty ("Mc_name", _yscale, size_y);
"Mc_name" is the name of the MC, "_xscale" and "_yscale" refers to the MC X and Y points
Position, which is used to control the size of the MC. Its "size_x" and "size_y" for the setting of this MC specific large
A small number.
Iii. How to change its position:
An easy way to do this is to move the MC that has been placed into the movie file, like we used to change a
The position of the diagram, drag it with the mouse.
Another method is to use SetProperty to change the position of the MC.
SetProperty ("Mc_name", _x, "position_x");
SetProperty ("Mc_name", _y, "position_y");
"Mc_name" is the name of the MC, "_x" and "_y" refer to the X and Y coordinate points, and "position_x" and "
Position_y "is the exact value of the position.
I hope you can understand this simple tutorial! The above code is FLASH5 standard.
Author: Yuhua Stone
current 1/2 page   1 2 Next read the full text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.