00:00
00:00

As:Bad Ideas

10,528 Views | 67 Replies
New Topic Respond to this Topic

As:Bad Ideas 2005-12-05 16:00:26


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.

Response to As:Bad Ideas 2005-12-05 16:02:19


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.

Response to As:Bad Ideas 2005-12-05 16:03:46


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


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature

Response to As:Bad Ideas 2005-12-05 16:06:57


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


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature

Response to As:Bad Ideas 2005-12-05 16:07:00


while(anarchy = true) {

Better:
while(anarchy == true){

Even better:
while(anarchy){


BBS Signature

Response to As:Bad Ideas 2005-12-05 16:07:06


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.

Response to As:Bad Ideas 2005-12-05 16:07:38


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


wtfbbqhax

Response to As:Bad Ideas 2005-12-05 16:08:23


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());


Sup, bitches :)

BBS Signature

Response to As:Bad Ideas 2005-12-05 16:08:48


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.

Response to As:Bad Ideas 2005-12-05 16:09:21


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*) ?

Response to As:Bad Ideas 2005-12-05 16:10:13


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


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature

Response to As:Bad Ideas 2005-12-05 16:11:07


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

Response to As:Bad Ideas 2005-12-05 16:12:05


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


Sup, bitches :)

BBS Signature

Response to As:Bad Ideas 2005-12-05 16:13:07


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);


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature

Response to As:Bad Ideas 2005-12-05 16:15:32


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

Response to As:Bad Ideas 2005-12-05 16:24:56


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

Response to As:Bad Ideas 2005-12-05 16:29:14


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.

Response to As:Bad Ideas 2005-12-05 17:37:52


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);


Sup, bitches :)

BBS Signature

Response to As:Bad Ideas 2005-12-05 17:48:55


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)


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature

Response to As:Bad Ideas 2005-12-06 04:30:21


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.

Response to As:Bad Ideas 2005-12-07 10:34:27


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

Response to As:Bad Ideas 2005-12-07 10:41:21


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

Response to As:Bad Ideas 2005-12-07 10:41:49


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

Response to As:Bad Ideas 2005-12-07 10:45:36


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

Response to As:Bad Ideas 2005-12-07 10:52:55


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


BBS Signature

Response to As:Bad Ideas 2005-12-07 11:13:03


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

Response to As:Bad Ideas 2005-12-07 11:13:36


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.


Sup, bitches :)

BBS Signature

Response to As:Bad Ideas 2005-12-07 11:14:53


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.

Response to As:Bad Ideas 2005-12-07 11:20:22


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

Response to As:Bad Ideas 2005-12-07 11:22:02


getURL("ping www.newgrounds.com");