Some tips on loading _flash as

Source: Internet
Author: User
Recently in doing a flash, found a very strange problem, that is, loading progress bar is starting from 64%, and the progress bar appeared before, a blank, but upload space, but found loding completely ineffective, hope you help, I thought for 2 hours, The head is getting bigger. Here are the first two frames of code
First frame:
Totalb = _root.getbytestotal ();
loaded = _root.getbytesloaded ();
Trace (loaded);
per = Math.Round (loaded/totalb*100);
Trace (per);
_root.load_bar._xscale = per;
Loadper = per+ "%";
Second frame:
if (LOADED>=TOTALB) {
gotoAndPlay ("Scene 1", 1);
}
else{
gotoAndPlay (1);
}
Thanks for the first!

Stop ()
_root.createemptymovieclip ("Loading_mc", _root.getnexthighestdepth ())
Loading_mc.beginfill (0x5f6165)
Loading_mc.moveto (0, 10);
Loading_mc.lineto (0, 0);
Loading_mc.lineto (350, 0);
Loading_mc.lineto (350, 10);
Loading_mc.lineto (0, 10);
loading_mc._x=200
loading_mc._y=350
_root.createtextfield ("Loading_txt", _root.getnexthighestdepth (), 200,370,30,20)
Loading_txt.border=false
Loading_txt.multiline = true;
Loading_txt.wordwrap = true;
Loading_mc.onenterframe=function () {
if (_root.getbytesloaded () >=_root.getbytestotal ()) {
_root.play ()
_root. Loading_mc.removemovieclip ()
_root. Loading_txt.removetextfield ()
}else{
_root. Loading_mc._xscale= (_root.getbytesloaded ()/_root.getbytestotal ()) *100
_root. Loading_txt.text=int (Loading_mc._xscale). toString () + "%"
_root. loading_txt._x=loading_mc._width+200
}
}


It's OK to put it on frame 1th.

Code interpretation:
1 Let the movie stop playing at frame 1th;
2 Create a movie clip at the root path, which is the _root location, whose name is LOADING_MC, and its layer is deeply rooted in the first layer that is not currently used in the root path.
3 LOADING_MC film clips are filled with 0x5f6165 color;
4~8 move it to the X:0,y:10 position to start drawing, coordinates 0~350, height is 10;
9 its x-coordinate is equal to 200;
10 its Y coordinate is equal to 300;
11 in the root path to establish a text field, its name is loading_txt, its layer deep root path is not used in the last layer depth, its x-coordinate is 200,y coordinates 370, width is 30, height is 20;
12 its Border property border is false, that is, it does not have a border;
13 It can be multiple lines of text;
14 It can change lines automatically;
15 when the LOADING_MC movie clip starts playing, each play one frame, executes the following code once;
16 when the root path has already loaded bytes, exceeding or equal to its total byte;
17 paths begin to play;
18 and delete loading_mc this film clip;
19 by deleting loading_txt this field;
20 if the conditions are not tenable;
LOADING_MC the width scale of the movie clip, equal to the downloaded byte of the root path divided by the total byte of the root path, multiplied by 100;
Loading_txt the text content of the field, equal to the width of the scale of the value, after rounding, then converted to the character type, and then add the "%" percent sign;
23 and its coordinates are equal to the width of the LOADING_MC movie clip plus 200.

Thank you very much for Elocho's answer, but I think my question may be a little different because, even if I add the following two lines to the first frame
Trace ("Loaded");
Stop ();
It also took a long time to show loaded, and the progress bar stopped at 64%,
I think the movie is not loaded until 64% to start executing my code, I put the code in scene 1, the main movie put in Scene 2

Maybe I'm not right, just for reference.
First, I don't know what version you use, but your variable doesn't specify a data type.
Second, check the first frame, what big things do not. Don't put it in frame 1th.
Its third, _root.load_bar._xscale = per; This means that each is a numeric type, but. loadper = per+ "%" does not convert the data type to operate.
Its four, _root.getbytesloaded (); What do you mean by this scenario? If you want the whole thing, use _global.
Its five, gotoAndPlay ("Scene 1", 1), the use of Chinese characters to do the scene name, is not a procedure recommended by the practice.
What do you mean by six, Math.Round ()? Is it rounded? not accurate, change int bar.


Summary: Others are small problems, _root replaced by _global, may be the main problem,
Related Article

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.