 |
 |
 |
 |
January 14th, 2004, 08:11 PM
|
#1
|
|
Registered User
Join Date: Jan 2004
Posts: 40
|
How to's
I posted one already, but I think I may be posting more, and don't want to clog the forum with repeating "How to: ____" threads. I have been working hard with Flash MX, more specifically the Actionscript part, for a while, and I will try to answer the common questions I have encountered. If the mod's and admin don't mind, I would like to extend my services here ( for free of course) and explain how to do somethin in Flash. I'll get the ball rollin'!
1 frame Bar Preloader with Percentage Text
I Can't tell you how many times I have come across this in other forums. Pretty easy once you get the hang of the coding.
- 1. Make a movieclip with a rectangle. Make sure the "registration point" is on the far left.
- 2. Once the rectangle is made into a movieclip, it should look like this:
_______________________________
|
|
+
|
|______________________________
The + sign is the registration point
If it doesn't line up properly, I apologize. 
Now, return to the main timeline, and open the actionscript editor. Click on the movieclip and add the code (in the panel):
Code:
onClipEvent (enterFrame) {
bytesL = _root.getBytesLoaded();
bytesT = _root.getBytesTotal();
perc = Math.round((bytesL/bytesT)*100);
_root.percent.text=perc+"%"
this._xscale = perc;
_root.name._alpha=perc
if(_root.percent.text=="100%){
_root.play()
delete this.onEnterFrame
}
}
- Now, somewhere on the main timeline (not inside the movieclip), make a Dynamic Text Box with the Instance Name of "percent".
This will make a few variables based on the total bytes and loaded bytes of the .swf, and then round that number, add a percent sign, and put it into the dynamic textbox named "percent".
All done!
|
|
|
January 14th, 2004, 10:57 PM
|
#2
|
|
Registered User
Join Date: Jan 2004
Location: Houston, TX
Posts: 17
|
only thing i disagree with is this part
PHP Code:
if(_root.percent.text=="100%){
why compare it to a text field? just compare it to the original variable, perc. makes it much less confusing. also i like to add a small buffer after its loaded but before it starts playing. something like this
PHP Code:
lBytes = this.getBytesLoaded();
tBytes = this.getBytesTotal();
percentLoaded = Math.floor((lBytes/tBytes)*100);
loader.bar._xscale = percentLoaded;
if (lBytes>=tBytes && tBytes>0) {
if (count>=2) {
gotoAndPlay("main");
} else {
count++;
gotoAndPlay("preloader");
}
} else {
gotoAndPlay("preloader");
}
keyframe on frame 1 of labels layer, with label of preloader. keyframe on frame 3 of labels layer with label of main and keyframe on frame 2 of actions layer with the above code.
|
|
|
January 14th, 2004, 11:26 PM
|
#3
|
|
Registered User
Join Date: Jan 2004
Posts: 40
|
Agreed. For some reason, it just doesn't work when I compare. I've tried:
And every variation of it. Ack, I dunno. Such a small and trivial problem.
As for your buffer, it works, but is a bit confusing for the newbies. "count++"? Both you and I know, but for those starting out may be more than needed. Usually I just have the bar fade out so it is more visually friendly, and some time to "settle" or whatnot before the movie begins.
Thanks MG.
-Steve
|
|
|
January 15th, 2004, 11:47 PM
|
#4
|
|
Registered User
Join Date: Jan 2004
Posts: 40
|
Elasticity
This is a fun one. Not usually seen in the real world, but a fun effect nonetheless. Uses some math.
On any Movieclip:
PHP Code:
onClipEvent (load) {
// inertia relates to the quantity of energy that
// the spring will carry
// inertia = 1 would mean that the spring doesn't
// loose any energy, and that it will oscillate
// forever
inertia = 0.9;
// k relates to the spring, and how "hard" it will be.
// The higher k the faster the mass will come back.
k = 0.1;
}
onClipEvent (enterFrame) {
// We calculate the distance to the mouse
x = -this._x+_root._xmouse;
y = -this._y+_root._ymouse;
//We calculate the amount by which the mass will to move
xp = xp*inertia+x*k;
yp = yp*inertia+y*k;
//We move it
_x += xp;
_y += yp;
}
On MX04, you have to predefine what xp is, and that can be confusing at times. In Flash 6, xp and yp are jsut added onto each other as the FPS goes on. So the load event in MX04 would look like:
PHP Code:
onClipEvent (load) {
inertia = 0.9;
k = 0.1;
xp=0
yp=0
}
Now, this can be modified to make the MC move as a menu item, button, or anything else. It doesn't have to be limited to the mouse. For example, this:
PHP Code:
onClipEvent (load) {
_x = 0
_y = 18;
inertia = 0.92;
k = 0.2;
}
onClipEvent (enterFrame) {
x = -this._x+160;
//We calculate the amount by which the mass will to move
xp = xp*inertia+x*k/3;
//We move it
_x += xp;
if (Math.abs(xp<.4)) {
delete this.onEnterFrame;
}
}
...looks confusing, but is a nice, light effect.
Feel free to ask questions! I know there are some!
-Steve
|
|
|
January 16th, 2004, 10:26 PM
|
#5
|
|
Registered User
Join Date: Jan 2004
Location: Houston, TX
Posts: 17
|
|
|
|
January 17th, 2004, 03:01 AM
|
#6
|
|
Registered User
Join Date: Jan 2004
Posts: 40
|
As far as I know, there's only one way to do this. I didn't plagarize (sp?), if that is what you are hinting...
|
|
|
January 17th, 2004, 09:22 AM
|
#7
|
|
Registered User
Join Date: Jan 2004
Location: Houston, TX
Posts: 17
|
i'm not saying that, i just provided a link that had a little more explanation in it
|
|
|
January 31st, 2004, 10:41 PM
|
#8
|
|
Registered User
Join Date: Jan 2004
Posts: 40
|
Masking Dynamic Text
I have had the displeasure of using dynamic text in MovieClips that are masked. The only way around it is to embed the font (see attached image). If you don't embed the fonts, they won't show up in the masked area.
When you do, however, the text is very fuzzy and in my opinion, sometimes isn't worth using the method because it looks so bad!
-Steve
|
|
|
February 9th, 2004, 08:42 PM
|
#9
|
|
Registered User
Join Date: Jan 2004
Posts: 40
|
Loading External Variables
There are a few ways to go about this, but I have found this is all I need for simple functions.
In Notepad (or something similar) type the variable name and the content with this format:
The & character tells Flash that this is the beginning of a new variable. the varName is the name of the variable. Can be anything except a number or a name with spaces. value is what you want it to contain. No quotes are necessary, can have spaces, etc. Save the file as "variables.txt"
In Flash, on the timeline, have:
Code:
loadVariablesNum("variables.txt", 100);
This loads and stores the variables in that text document to level 100. That number can be anything
Now that everything is loaded, lets do something with it. Lets say you want a few different stories on button clicks. In the notepad, write this:
Code:
&story1=Goldylocks
&story2=Little Red Riding Hood
&story3=The 3 Little Bears
Make a textbox on the timeline with the instance name of "textbox". Then make three buttons. On button one, have:
Code:
on(release){
_root.textbox.text=_level100.story1
}
This will make the textbox show "Goldylocks" when you press the button. Repeat this for each of the other buttons and presto!
-Steve
|
|
|
February 19th, 2004, 04:42 PM
|
#10
|
|
Registered User
Join Date: Jan 2004
Location: Houston, TX
Posts: 17
|
yeah that no dynamic text with masks thing really messed me up. i probably spent 4 days trying to get it to work when i finally gave up and stuck with static text. i was trying to do it with this site i recently did for a client:
www.williampear.com
go to a page like about us and you'll see how the text is masked. i guess when its time to make the html version we'll just need to make changes to both instead of a single database like originally planned.
|
|
|
February 27th, 2004, 09:48 PM
|
#11
|
|
Registered User
Join Date: Jan 2004
Posts: 40
|
Yea, it really stinks that Macromedia hasn't fixed it yet 
|
|
|
June 26th, 2004, 09:58 PM
|
#12
|
|
Account Disabled
Join Date: Jun 2004
Location: Newnan Georgia
Posts: 112
|
Wow, You really know your stuff. I'm still learning Flash and that is all greek to me.
|
|
|
June 27th, 2004, 04:25 PM
|
#13
|
|
Registered User
Join Date: Jun 2004
Location: Surrey, BC
Posts: 184
|
I know how to make very very basic flash movies but I don't know jack about the code, nor did I even know about the code until this point 
|
|
|
July 16th, 2004, 04:49 PM
|
#14
|
|
Registered User
Join Date: Jun 2004
Location: South Amboy NJ
Posts: 107
|
Quote:
Originally posted by Fabolous05
I know how to make very very basic flash movies but I don't know jack about the code, nor did I even know about the code until this point
|
Same here Fab - I can make a simple flash movie but I didnt know there was any kind of code that went with it...
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:54 AM.
|
|
 |
 |
 |
 |
|