|
 |
|
Tutorialized Forums
> 2D Graphics
> Flash
|
Script Refence
Discuss Script Refence in the Flash forum on Tutorialized. Script Refence Flash forum coverting topics such as creating standalone movies, interactive demos, or cool web components, Flash is a solid foundation on which to base your work. Discuss how to work in 3D, drawing techniques, and more.
|
|
 |
|
|
|
|

Tutorialized Forums Sponsor:
|
|
|

June 13th, 2008, 08:08 PM
|
 |
Moderator
|
|
Join Date: Oct 2006
Posts: 446
Time spent in forums: 2 Days 7 h 33 m 20 sec
Reputation Power: 7
|
|
|
Knowledge Base (KB)
This thread will contain some commonly used scripts, which may be specialised, or generalised. That is, for a specific purpose, or a general script for you to modify.
Shorthand used:
In description:
mc: movieclip
btn: button
obj: object
lstr: Listener
In code:
mc: Insert your movieclips instance name here
btn: Insert your buttons instance name here
obj: Insert your objects instance name here
lstr: Insert your listeners name here
NOTE: All code given here belongs on the frame, unless specifically stated. Please only reply here if you want to request something to be added to here, or you have an addition of your own.
--------------------------------------------
Key Movement:
Code:
//Uncomment the 'elses' to prevent the object from moving diagonally.
mc.onEnterFrame = function() {
if (Key.isDown(Key.LEFT)) {
this._x -= 10;
}
//else
if (Key.isDown(Key.RIGHT)) {
this._x += 10;
}
//else
if (Key.isDown(Key.UP)) {
this._y -= 10;
}
//else
if (Key.isDown(Key.DOWN)) {
this._y += 10;
}
};
Key Movement with listeners:
--Using listeners will make your program run faster, as the program is not constantly checking for if statements.
Code:
//Uncomment the 'elses' to prevent the object from moving diagonally.
var lstr:Object = new Object();
lstr.onKeyDown = function() {
if (Key.isDown(Key.LEFT)) {
mc._x -= 10;
}
//else
if (Key.isDown(Key.RIGHT)) {
mc._x += 10;
}
//else
if (Key.isDown(Key.UP)) {
mc._y -= 10;
}
//else
if (Key.isDown(Key.DOWN)) {
mc._y += 10;
}
};
Key.addListener(lstr);
Commonly used conditions.
Code:
if (a>b) {
//If a is bigger then b
}
if (a<b) {
//If a is smaller then b
}
if (a>=b) {
//If a is bigger or equal to b.
}
if (a<=b) {
//If a is smaller or equal to b.
}
if (a==b) {
//If a is equal to b.
}
if (a!=b) {
//If a does not equal b.
}
if (!a==b) {
/*Another way of saying the above, obviously you can replace the '==' with whatever conditions you want.*/
}
Duplicate Movie's:
Code:
//Portable function, m is the x property of the original movieclip.
//i is just a counter that begins at 1.
duplicate = function (m, i) {
duplicateMovieClip(ball, "ball"+i, getNextHighestDepth());
setProperty("ball"+i, _x, m);
if (i <= 20) {
duplicate(m+=20, i+=1);
}
};
Collision Detections:
There are many ways to do this, here are a few.
Code:
mc.onEnterFrame = function() {
if (mc1.hitTest(other_mc)) {
//Do what you want when the object hits the other object.
}
}
From Ismael92:
Code:
your_mc.onEnterFrame = function() {
if (your_mc, hitTest(your_other_mc)) {
//put here what you want to happen if your movie clips are colliding;
} else {
//you can put something here if you want something to happen when the movie clips are NOT colliding;
}
}
Adding flash files to websites:
Loong's tutorial
--------------------------------------------------------------
Credits:
Our thanks go to:
Ismael92
loong
for contributing to this reference.
ZackAttack667
for requesting scripts.
__________________
Flash and HTML nut.
Hey. Learn how to wite XHTML, stop using dreamweaver! =)
Contact me at:
Send a mesage to John Doe
Last edited by thunder : October 16th, 2008 at 04:51 AM.
|

July 14th, 2008, 04:56 PM
|
|
Registered User
|
|
Join Date: Jul 2008
Posts: 3
Time spent in forums: 6 h 45 m
Reputation Power: 0
|
|
Well, i'll put some collision detection (AS2)
Code:
onClipEvent (enterFrame) {
if (your_mc, hitTest(your_other_mc)) {
//put here what you want to happen if your movie clips are colliding;
} else {
//you can put something here if you want something to happen when the movie clips are NOT colliding;
}
}
Of course, replace your_mc and your_other_mc with the name of your movie clips.
Cheers
Last edited by thunder : July 19th, 2008 at 04:09 AM.
|

July 19th, 2008, 04:15 AM
|
 |
Moderator
|
|
Join Date: Oct 2006
Posts: 446
Time spent in forums: 2 Days 7 h 33 m 20 sec
Reputation Power: 7
|
|
|
Added to Script Reference, thankyou, keep em coming.
Last edited by thunder : July 25th, 2008 at 05:20 PM.
|

July 19th, 2008, 09:27 PM
|
|
Contributing User
|
|
Join Date: Jul 2007
Location: Seoul Korea
Posts: 61
Time spent in forums: 17 h 43 m 3 sec
Reputation Power: 6
|
|
|
I'd like to request an actionscript function. The ability to duplicate a movieclip is very commonly used in games, and I'm making a game currently. It would help me a lot to know a way to efficiently duplicate a movieclip.
|

July 25th, 2008, 06:08 PM
|
 |
Moderator
|
|
Join Date: Oct 2006
Posts: 446
Time spent in forums: 2 Days 7 h 33 m 20 sec
Reputation Power: 7
|
|
|
Thankyou Zack, I have added the duplicate movie function to the reference.
Keep the requests and submissions coming guys!
|

August 4th, 2008, 03:01 AM
|
|
Registered User
|
|
Join Date: Aug 2008
Posts: 2
Time spent in forums: 1 h 25 m 33 sec
Reputation Power: 0
|
|
|
Good method
Thanks ! that was good script for this method.
Deleted by Thunder - Off topic much? Spam removed. Watch it, or I will add a warning.
Last edited by thunder : August 18th, 2008 at 05:31 AM.
|

May 27th, 2009, 08:11 AM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 1
Time spent in forums: 36 m 4 sec
Reputation Power: 0
|
|
|
Stop navigation jumps
Hello everybody,
I hope I am right in this forum.
I just started with Flash and find it an amazing tool for webapplications.
As a beginner I started to do a webside what went quite well so far.
On the test side (checking my AS code) I have three buttons.
When you press a button01, object01 is moving on the stage by Movement tween. When you press button02 the object01 is leaving the stage and object02 is moving in (it was hard enough to figure that out ... :-). the same goes for button03 and object03. Whenever you press a button the last object leaves the stage first before the next object moves in.
So far so good.
While testing the script I realized that the whole thing gets messed up if you dont wait till the end of the movement of the objects.
Instead of the expected moevement there is no movement at all. I press button01 nad object02 is "Jumping" not moving in. Its nervewrecking and I dont find a solution so far.
I include a sample of my script with further informations and hope someone can help.
Script on the button objects (Not on the frame), the frames to go are different for each button of course.
******
on (release){
FrameCount = 1;
if (FrameAim == 0){
gotoAndPlay (2);
}
if (FrameAim == 80){
gotoAndPlay (80);
}
if (FrameAim == 135){
gotoAndPlay (135);
}
FrameAim = 25;
}
******
This is the script on the last frame of every "segment" of the movie. (3 buttons, 3 segments)
******
if (FrameCount == 2){
gotoAndPlay (55);
}
if (FrameCount == 3){
gotoAndPlay (110);
}
******
|

November 24th, 2011, 07:05 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 1
Time spent in forums: 15 m 39 sec
Reputation Power: 0
|
|
|
Wow..That's really a great post. I think is very useful for all flash users. Keep it up.
|

September 10th, 2012, 03:54 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 65
Time spent in forums: 7 h 52 m 22 sec
Reputation Power: 2
|
|
Quote: | Originally Posted by trytan Hello everybody,
I hope I am right in this forum.
I just started with Flash and find it an amazing tool for webapplications.
As a beginner I started to do a webside what went quite well so far.
On the test side (checking my AS code) I have three buttons.
When you press a button01, object01 is moving on the stage by Movement tween. When you press button02 the object01 is leaving the stage and object02 is moving in (it was hard enough to figure that out ... :-). the same goes for button03 and object03. Whenever you press a button the last object leaves the stage first before the next object moves in.
So far so good.
While testing the script I realized that the whole thing gets messed up if you dont wait till the end of the movement of the objects.
Instead of the expected moevement there is no movement at all. I press button01 nad object02 is "Jumping" not moving in. Its nervewrecking and I dont find a solution so far.
I include a sample of my script with further informations and hope someone can help.
Script on the button objects (Not on the frame), the frames to go are different for each button of course.
******
on (release){
FrameCount = 1;
if (FrameAim == 0){
gotoAndPlay (2);
}
if (FrameAim == 80){
gotoAndPlay (80);
}
if (FrameAim == 135){
gotoAndPlay (135);
}
FrameAim = 25;
}
******
This is the script on the last frame of every "segment" of the movie. (3 buttons, 3 segments)
******
if (FrameCount == 2){
gotoAndPlay (55);
}
if (FrameCount == 3){
gotoAndPlay (110);
}
****** |
Being a web programmer i know its importance, Many places I tried to find this code till now but this thread is first one. Great work.
|

November 16th, 2012, 11:38 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 1
Time spent in forums: 10 m 50 sec
Reputation Power: 0
|
|
|
This is a good script . Thanks !!!!!!
|

January 10th, 2013, 01:28 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 26 m 40 sec
Reputation Power: 0
|
|
|
Developer Shed Advertisers and Affiliates
| 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
|
|
|
|
|