View Full Version : coding practices opinions
Paul Ferrie
10-15-2005, 06:28 PM
I am wondering what is more code/CPU/ efficient
x amount of buttons with:
bt1.onRollOver = function() {
tTip._x = _xmouse+10;
tTip._y = _ymouse+10;
tTip.tTip.text = "some text";
tTip._visible = 1;
onMouseMove = function () {
tTip._x = _xmouse+10;
tTip._y = _ymouse+10;
};
};
or
bt1.onRollOver = function() {
fader(bt1);
};
bt2.onRollOver = function() {
fader(bt2);
};
function fader(me){
if(me=="bt1"){
tTip._x = _xmouse+10;
tTip._y = _ymouse+10;
tTip.tTip.text = "add some text";
tTip._visible = 1;
onMouseMove = function () {
tTip._x = _xmouse+10;
tTip._y = _ymouse+10;
};
}if(me=="bt2"){
tTip._x = _xmouse+10;
tTip._y = _ymouse+10;
tTip.tTip.text = "Add some text";
tTip._visible = 1;
onMouseMove = function () {
tTip._x = _xmouse+10;
tTip._y = _ymouse+10;
}
And soon on.
Whats your opinion?
snapple
10-15-2005, 07:00 PM
I don't know lots about the ins-and-outs of the Flash compiler. However, a general good rule of thumb is; the less code the quicker. I am good at Big-O notation, but that cannot be used in your code.
So i would say, the first statement you posted would be easier on the compiler.
Hope this helps, bet it does not, but hey.
Regards, snapple
Paul Ferrie
10-15-2005, 07:14 PM
Big-O notation
??
Here's what i got the code down to
// util buttons
// add colour to text
btColor.onRollOver = function() {
toolTip("Add colour to text");
};
btColor.onReleaseOutside = function() {
faderOut();
};
btColor.onRollOut = function() {
faderOut();
};
// Add link to text
btLink.onRollOver = function() {
toolTip("Add http link");
};
btLink.onReleaseOutside = function() {
faderOut();
};
btLink.onRollOut = function() {
faderOut();
};
// Add mail to text
btMail.onRollOver = function() {
toolTip("Add email link");
};
btMail.onReleaseOutside = function() {
faderOut();
};
btMail.onRollOut = function() {
faderOut();
};
//
function toolTip(me) {
tTip._x = _xmouse+10;
tTip._y = _ymouse+10;
tTip.tTip.text = me;
faderIn();
onMouseMove = function () {
tTip._x = _xmouse+10;
tTip._y = _ymouse+10;
};
}
// fader function for tool tip
// Fade in
function faderIn() {
trace("fader running");
this.onEnterFrame = function() {
if (tTip._alpha<100) {
tTip._alpha += 20;
}
if (tTip._alpha>=95) {
delete this.onEnterFrame;
}
};
}
// Fade out
function faderOut() {
this.onEnterFrame = function() {
if (tTip._alpha>0) {
tTip._alpha -= 20;
}
if (tTip._alpha<=0) {
delete this.onEnterFrame;
}
};
}
I am well chuffed. Even if it did take the best part of 4 hours
i have some similair Question
and i think
the less code the quicker
isn't true !?
trace(1)
trace(2)
trace(3)
trace(4)
trace(5)
for (a=1;a<6;a++){
trace(a)}
i think the 1. shoud by faster
let say it's an extreme and i have 10000 traces (or what code ever)
so the file size shoud by 10000 times biger/longer
but code execution shoud by faster !?
snapple
10-15-2005, 07:21 PM
The Big O notation is a mathematical notation used to describe the asymptotic behavior of functions.
It is a way to formally derive how efficiant an algorithm or function is.
Regards, snapple
Paul Ferrie
10-15-2005, 07:31 PM
So it's like "power tweaking" a function?
Do as much as possible with as little code as possible?
Thats sounds familiar...
Ahhh
Do as little work earn as much as possible :)
apotropaic
10-15-2005, 09:59 PM
Maybe check this website out:
http://www.gotoandplay.it/_articles/2004/01/as_optimizations.php
Paul Ferrie
10-15-2005, 10:05 PM
Damn that looks like a good read. Will be having a right good gander over that tomorrow.
Thanks
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.