Flash

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized Forums2D GraphicsFlash

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old June 13th, 2008, 08:08 PM
thunder's Avatar
thunder thunder is offline
Moderator
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 446 thunder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 7 h 33 m 20 sec
Reputation Power: 9
Send a message via MSN to thunder Send a message via Google Talk to thunder
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.

Reply With Quote
  #2  
Old July 14th, 2008, 04:56 PM
Ismael92 Ismael92 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 3 Ismael92 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #3  
Old July 19th, 2008, 04:15 AM
thunder's Avatar
thunder thunder is offline
Moderator
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 446 thunder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 7 h 33 m 20 sec
Reputation Power: 9
Send a message via MSN to thunder Send a message via Google Talk to thunder
Added to Script Reference, thankyou, keep em coming.

Last edited by thunder : July 25th, 2008 at 05:20 PM.

Reply With Quote
  #4  
Old July 19th, 2008, 09:27 PM
ZackAttack667 ZackAttack667 is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Seoul Korea
Posts: 61 ZackAttack667 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 43 m 3 sec
Reputation Power: 8
Send a message via AIM to ZackAttack667 Send a message via MSN to ZackAttack667
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.

Reply With Quote
  #5  
Old July 25th, 2008, 06:08 PM
thunder's Avatar
thunder thunder is offline
Moderator
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 446 thunder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 7 h 33 m 20 sec
Reputation Power: 9
Send a message via MSN to thunder Send a message via Google Talk to thunder
Thankyou Zack, I have added the duplicate movie function to the reference.

Keep the requests and submissions coming guys!

Reply With Quote
  #6  
Old August 4th, 2008, 03:01 AM
madyu madyu is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Posts: 2 madyu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #7  
Old May 27th, 2009, 08:11 AM
trytan trytan is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 1 trytan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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);
}
******

Reply With Quote
  #8  
Old November 24th, 2011, 07:05 AM
jonathan2340 jonathan2340 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 jonathan2340 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #9  
Old September 10th, 2012, 03:54 PM
Jason Martin Jason Martin is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 53 Jason Martin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 52 m 22 sec
Reputation Power: 3
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.

Reply With Quote
  #10  
Old November 16th, 2012, 11:38 PM
monju25 monju25 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 monju25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 50 sec
Reputation Power: 0
This is a good script . Thanks !!!!!!

Reply With Quote
  #11  
Old January 10th, 2013, 01:28 AM
Trenton9claude Trenton9claude is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 Trenton9claude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 40 sec
Reputation Power: 0
It would help me a lot to know a way to efficiently duplicate a movieclip.
URL
URL
URL
URL
URL

Reply With Quote
Reply

Viewing: Tutorialized Forums2D GraphicsFlash > Script Refence


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap