Forum Topic: As:Bad Ideas

(6,809 views • 68 replies)

This topic is 3 pages long. [ 1 | 2 | 3 ]

<< < > >>
Shouting

Fire

Reply To Post Reply & Quote

Posted at: 12/5/05 04:00 PM

Fire DARK LEVEL 15

Sign-Up: 10/29/03

Posts: 2,935

NOT As:Main

Disclaimer: I am providing this info for educational purposes ONLY. I am not encouraging malicious or buggy flash content designed by info provided in this thread. Me, and the repliers to this thread, are not responsible for you messing up your computer and losing data.

Okay, now that that's out of the way, lets get to the tutorial.

These are some things you shouldn't do when using Actionscript, the effects range from freezing your computer to buggy games.

1:Deprecated AS
Deprecated Actionscript can be used, but will probably become obsolete (Not used by future versions of Flash) in a few years. These are a few deprecated actions in Flash MX.

A:tellTarget
used like:
tellTarget (_root) {
gotoAndPlay(161);
}
use _root.gotoAndPlay(161); instead.
B:toggleHighQuality
used like:
on(press) {
toggleHighQulaity();
}
I dont know the replacement, but it has something to do with the _quality global.
C:Logical operators
this:
//ALL "and" and "or" operators are deprecated in MX.
if(fire == true and water == false or onFire == true and u_r_fucked == true) {
gotoAndPlay("death") //Just had to do that.
}
would become this:
if(fire == true && water == false || onFire == true && u_r_fucked == false) {
gotoAndPlay("death") //Much faster "death". Okay I'll stop
}
There are tons more, but these are major ones. To see them all click the plus sign above the Actions window and select "Deprecated".

2:Loop abuse
Loops can freeze someones computer, and are used in websites such as Last Measure (Actuatlly I think it uses some other script, but the same effect can be created using Actionscript)

A:Trace
Sample code:
anarchy = true
while(anarchy = true) {
trace("I am fucking up your computer. Give me $1,000,000");
}
The following will really lock a computer up:
//create a dynamic text box named "owned"
for(i=0;i=infinity;i++) {
owned.text = i
trace(i);
}
Remember my disclaimer, mods.
3:Stupid math
Really the only things that fit in here are:
1.Using deprecated math operators
2. Dividing by 0
If you divide by 0, you will mess up your game.
3. Abusing bitwise
like:
on(release){
Score = 2 << 10000000000
}
Just don't do it, it can slow really old computers down to turtle pace.
4:Everything else
A:getURL abuse
Linking to the flash itself:
//Frame 1
getURL('www.example.com/flash/idiot.swf',b
lank /* I know it isnt right */);
The flash will open itself forever, causing the user to restart his/her browser.
B:Volume
The following will turn it up to max:
myHeavyMetalRock.setVolume(100):Void //Used with a sound object

Be sure to post your own bad ideas, and remember this is for educational purposes only.


None

Blaze

Reply To Post Reply & Quote

Posted at: 12/5/05 04:02 PM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

sweet... thats very good to know. Great tut.

Is creating a while(); looping and doing it unproperly also a bad idea? because it normally crashes flash. and maybe the user's computer.


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 12/5/05 04:03 PM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,546

a == true is just a
a == false is just !a

the == true and == false isnt necesary:

also

for(i=0;i<infinity;i++) not i=infinity, nor would it be i==infinity
a few other cases like that, but nvm lol

nice tutorial explaining the simple mishaps of AS

My social worker says im special!

BBS Signature

None

dELtaluca

Reply To Post Reply & Quote

Posted at: 12/5/05 04:06 PM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,546

oh also, another deprecated function is random(#) which sucks since its a great easy function, in AS3 it has been removed and you must use Math.random() which to create the same function as random(#) would be Math.round(Math.random()*#) (# is an integer) which is quite obviously slower to compute, and Math.random() is slower to compute than random(#) in the first place anyways

My social worker says im special!

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 12/5/05 04:07 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

while(anarchy = true) {

Better:
while(anarchy == true){

Even better:
while(anarchy){


None

Fire

Reply To Post Reply & Quote

Posted at: 12/5/05 04:07 PM

Fire DARK LEVEL 15

Sign-Up: 10/29/03

Posts: 2,935

At 12/5/05 04:03 PM, -dELta- wrote: a == true is just a
a == false is just !a

the == true and == false isnt necesary:

sure I'll remember that.


None

fwe

Reply To Post Reply & Quote

Posted at: 12/5/05 04:07 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

while(true) for(;;) while(1==1) for(k=0;k>0;k-+) omigawsh

wtfbbqhax


None

liaaaam

Reply To Post Reply & Quote

Posted at: 12/5/05 04:08 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,534

At 12/5/05 04:02 PM, Xmas_Blaze wrote: while();

While
while(a==5){
trace("a is five");
}

Proper usage:

while(a==5){
a--;
}

Copying and pasting code
JUST FUCKING DON'T >: (

For loops (again)
BitmapData.prototype.coloursUsed = function():Array {
var arr:Array = new Array();
for(a=0;a<this.length;a++){
for(b=0;b<this.width;b++){
arr.push(this.getPixel(a, b));
}
}
return arr;
}
import flash.display.BitmapData;
bmp= new BitmapData(550, 400, false, 0x000000);
trace(bmp.coloursUsed());


None

Fire

Reply To Post Reply & Quote

Posted at: 12/5/05 04:08 PM

Fire DARK LEVEL 15

Sign-Up: 10/29/03

Posts: 2,935

At 12/5/05 04:06 PM, -dELta- wrote: oh also, another deprecated function is random(#) which sucks since its a great easy function, in AS3 it has been removed and you must use Math.random() which to create the same function as random(#) would be Math.round(Math.random()*#) (# is an integer) which is quite obviously slower to compute, and Math.random() is slower to compute than random(#) in the first place anyways

I was gonna put that in but I didnt know if they were gonna put it back in. That is a reason I'm sticking with MX.


None

Blaze

Reply To Post Reply & Quote

Posted at: 12/5/05 04:09 PM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

At 12/5/05 04:06 PM, -dELta- wrote: oh also, another deprecated function is random(#) which sucks since its a great easy function, in AS3 it has been removed and you must use Math.random() which to create the same function as random(#) would be Math.round(Math.random()*#) (# is an integer) which is quite obviously slower to compute, and Math.random() is slower to compute than random(#) in the first place anyways

isnt using Math.random better than just going random(); ?

And... what happens if you use random(#); or did you mean random(*insert number here*) ?


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 12/5/05 04:10 PM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,546

another simple, but stupid mistake:

while(true) {} lol

some people might not see whats wrong with this: its often hidden like you had it as a variable
var anarchy:Boolean = true;
while(anarchy) {}; some people might not see the error, but in essence thats just while(true) {}

(not that im closing the while loop straight away to shore that the anarchy variable is never manipulated and will always be true)

another one:

for(var i:Number = 0; i>-10; i++) {}

obiovusly the person is wanting a decremental loop from 0 to -9, but has used i++ by mistake, can sometimes be frustrating to realise when debugging a large code

My social worker says im special!

BBS Signature

None

fwe

Reply To Post Reply & Quote

Posted at: 12/5/05 04:11 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

At 12/5/05 04:09 PM, Xmas_Blaze wrote:
At 12/5/05 04:06 PM, -dELta- wrote:
(# is an integer)
And... what happens if you use random(#); or did you mean random(*insert number here*) ?

Yes, you idiot

wtfbbqhax


None

liaaaam

Reply To Post Reply & Quote

Posted at: 12/5/05 04:12 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,534

At 12/5/05 04:11 PM, fwe wrote:
At 12/5/05 04:09 PM, Xmas_Blaze wrote: And... what happens if you use random(#); or did you mean random(*insert number here*) ?
Yes, you idiot

Roffle, that's classic :D


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 12/5/05 04:13 PM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,546

At 12/5/05 04:09 PM, Xmas_Blaze wrote: isnt using Math.random better than just going random(); ?

And... what happens if you use random(#); or did you mean random(*insert number here*)

depends what you mean by 'better', its more OOP, but slower

and yes, by random(#) i meant random(*insert number here*) i also did say that later when i said (# is an integer) since random(#) only takes integer parameters, i.e. you cant do random(0.5)

well you can, but in essence, random(a) is random(floor(a)) so random(2.7) is the same as random(2);

My social worker says im special!

BBS Signature

None

Blaze

Reply To Post Reply & Quote

Posted at: 12/5/05 04:15 PM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

At 12/5/05 04:13 PM, -dELta- wrote: depends what you mean by 'better', its more OOP, but slower

Oooh. Okay, get it.

and yes, by random(#) i meant random(*insert number here*) i also did say that later when i said (# is an integer) since random(#) only takes integer parameters, i.e. you cant do random(0.5)

True.

well you can, but in essence, random(a) is random(floor(a)) so random(2.7) is the same as random(2);

Random never gives decimals, as does Math.random. Am I wrong? (dont think i am). So, sometimes its better to use Math.random... But say, if i wanted it like

trace(Math.round(random(2.7));

What would that return? im curious right now. Wait... duh ill just try it myself. XD


None

Sir-Davey

Reply To Post Reply & Quote

Posted at: 12/5/05 04:24 PM

Sir-Davey FAB LEVEL 19

Sign-Up: 07/09/01

Posts: 3,093

dELta has this to say:

At 12/5/05 04:15 PM, Xmas_Blaze wrote: stuff

read what i said, random is essentialy random(floor ) meaning that random(2.7) is exactly the same in essence as random(2) since random only deals with integers, to be precise, unsigned integers, random when a is less than 0, will always be 0

Math.random() returns a DECIMAL number between 0 and 1 (excluding 1) to the max number of decimal places (14, since 1 digit is reserved for the integer in this case)

BBS Signature

None

Blaze

Reply To Post Reply & Quote

Posted at: 12/5/05 04:29 PM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

At 12/5/05 04:24 PM, Sir-Davey wrote: read what i said, random is essentialy random(floor ) meaning that random(2.7) is exactly the same in essence as random(2) since random only deals with integers, to be precise, unsigned integers, random when a is less than 0, will always be 0

Math.random() returns a DECIMAL number between 0 and 1 (excluding 1) to the max number of decimal places (14, since 1 digit is reserved for the integer in this case)

ooh. Thanks, and sorry for bothering so much. ^_^ Its just im starting to program, and i dont know, but im anxious to learn anything. Thanks dELta.


None

liaaaam

Reply To Post Reply & Quote

Posted at: 12/5/05 05:37 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,534

At 12/5/05 04:15 PM, Xmas_Blaze wrote: trace(Math.round(random(2.7));

Thats the same as doing trace(random(2.7);


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 12/5/05 05:48 PM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,546

At 12/5/05 05:37 PM, -Christmas- wrote:
At 12/5/05 04:15 PM, Xmas_Blaze wrote: trace(Math.round(random(2.7));
Thats the same as doing trace(random(2.7);

and the point i was getting at was that random(2.7) == random(2), or in general random(a) = random(floor(a)) and that negative numbers for random will always return 0; so in general random(a) = a<2 ? 0 : random(floor(a));

random(-1) = random(-15.6) = random(0) = random(0.5) = random(1) = random(1.98) = 0;
random(2.5) = random(2); random(3.9) = random(3), random(5.1) = random(5)

My social worker says im special!

BBS Signature

None

SpamBurger

Reply To Post Reply & Quote

Posted at: 12/5/05 05:53 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

Heres another one, never use duplicateMovieClip() in a onClipEvent(load){
You shouldnt do this becuase when MC's get duplicated, there code gets duplicated too. So, when every MC gets duplicated, it will create another dup, and it will keep doing this. It will crash your comp so dont do it.

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

ZYX3D

Reply To Post Reply & Quote

Posted at: 12/6/05 04:30 AM

ZYX3D DARK LEVEL 21

Sign-Up: 07/31/04

Posts: 437

At 12/5/05 04:15 PM, Xmas_Blaze wrote:
At 12/5/05 04:13 PM, -dELta- wrote:

(...):

Random never gives decimals, as does Math.random. Am I wrong? (dont think i am). So, sometimes its better to use Math.random...

Supposing you're dumb enough not to do random(27)*.1 , yes. It's the inverse proceeding as Math.round(Math.random*interval), in case you didn't notice. The point isn't "oh, this only gives decimals and this only gives integers", it's just something about how the "random" numbers are generated.


None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 12/7/05 10:34 AM

GuyWithHisComp LIGHT LEVEL 27

Sign-Up: 11/10/05

Posts: 4,010

At 12/5/05 04:08 PM, -Christmas- wrote: While
while(a==5){
trace("a is five");
}

What's the different of if and while?

BBS Signature

None

Voltnal

Reply To Post Reply & Quote

Posted at: 12/7/05 10:41 AM

Voltnal NEUTRAL LEVEL 07

Sign-Up: 07/31/05

Posts: 380

Any actionscripter capable of writing as advanced actionscript as said above would be intelligent enough to know not to divide by 0.


None

Claxor

Reply To Post Reply & Quote

Posted at: 12/7/05 10:41 AM

Claxor DARK LEVEL 10

Sign-Up: 10/21/05

Posts: 2,465

At 12/7/05 10:34 AM, GuyWithHisComp wrote: What's the different of if and while?

While does something over and over until the condition isn't met. If's only does it once

BBS Signature

None

Rantzien

Reply To Post Reply & Quote

Posted at: 12/7/05 10:45 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

At 12/7/05 10:34 AM, GuyWithHisComp wrote:
At 12/5/05 04:08 PM, -Christmas- wrote: While
while(a==5){
trace("a is five");
}
What's the different of if and while?

Basically, if checks the condition, runs the statement if the condition is true, and proceeds with the following code, while checks condition, if the condition is true it will run the statement until the condition is false, all in one frame. Basically. This means the actions in a while loop has to make the condition false sooner or later, otherwise you've got yourself an unbreakable loop there.

That's why this code, for example, is a bad idea:

i = 1;
while (i<1) {
i++;
}

It will crash your computer, because it will loop infinitely, since the condition never becomes false. The computer tries to compute infinite equations in the blink of an eye.

BBS Signature

None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 12/7/05 10:52 AM

GuyWithHisComp LIGHT LEVEL 27

Sign-Up: 11/10/05

Posts: 4,010

So while is kinda the same as
onClipEvent(enterFrame){
if(){}
}

BBS Signature

None

Rantzien

Reply To Post Reply & Quote

Posted at: 12/7/05 11:13 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

At 12/7/05 10:52 AM, GuyWithHisComp wrote: So while is kinda the same as
onClipEvent(enterFrame){
if(){}
}

No, it won't check once every frame, when triggered it will check, check again and again and again in the same frame, until the condition is not met.

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 12/7/05 11:13 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,534

At 12/7/05 10:52 AM, GuyWithHisComp wrote: So while is kinda the same as
onClipEvent(enterFrame){
if(){}
}

No, while does it all at once. It's similar to a for loop, you could replace:

var a:Number = 0;
while(a<5){
a++;
}

with:

for(a=0;a<5;a++){
a++;
}

It does the same thing (in that example at least), if you understand.


None

ZYX3D

Reply To Post Reply & Quote

Posted at: 12/7/05 11:14 AM

ZYX3D DARK LEVEL 21

Sign-Up: 07/31/04

Posts: 437

At 12/7/05 10:52 AM, GuyWithHisComp wrote: So while is kinda the same as
onClipEvent(enterFrame){
if(){}
}

This is a good example of AS:Bad idea, and bear this in mind the first time you use while(){}. No, they're very different things. The keypoint is, if checks just once then exits, while checks until condition is not true, then exits. With the onEnterFrame handler, the if will be checked periodically, with while the other processes will have to wait until it's done. This means that a bad executed while can literally stop your flash, while a bad executed if won't. Just try:

onClipEvent(enterFrame){if(1){trace("True"
)}; trace("If ended");}

and

while(true){trace("While on")}; trace("while ended");

Guess you'll see the difference.


None

Rantzien

Reply To Post Reply & Quote

Posted at: 12/7/05 11:20 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

At 12/7/05 11:14 AM, ZYX3D wrote: while(true){trace("While on")}; trace("while ended");

Just save all your work before you try that one.

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 04:39 AM

<< Back

This topic is 3 pages long. [ 1 | 2 | 3 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!