/    Sign up×
Community /Pin to ProfileBookmark

OO: A little object problem…

Hi everybody, ?

for a fade effect of a vector element i wrote this little prototpye, that you will find in code at the end of this post. It is nearly complete and last only an error, as i suppose, in the settings for access of the methodes.
The methode for timing “tween()” has to be accessed from the outside once, so it has to be public and that is working fine. Second it has to call it self over and over to animate the fading, that is in fact not working at all, because the methode can’t find it self. The error console tells me that tween() is not a function. ?

Anybody got a clue what’s the error may be?

Greets ?

Jens

By the way, i would most appreciate hints on javascript sources that hold good description on oo programming.

[CODE]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Fading Test</title>

<style type=”text/css”>
h1 {color: rgb(125,125,125); background-color: rgb(255,255,255);}
</style>

<script type=”text/javascript” src=”prototype.js”></script>
<script type=”text/javascript”>

Event.observe(window, ‘load’, function() {
var sRgb = new Array (125,125,125);
var tRgb = new Array (255,255,255);
Event.observe(‘button’, ‘click’, function() {
var nooo = new fadingVectorObject (sRgb, tRgb, ‘toFade’);
nooo.tween();
} );
} );

function fadingVectorObject (startColor, targetColor, id, steps, waitTime ) {

feedback(‘fadingVectorObject (startColor, targetColor, id, steps, time )’, ‘obj’);

var self = this;
this.startColor = startColor;
this.targetColor = targetColor;
this.id = id;

feedback(‘self(‘+self+’)’, ‘fix’);
feedback(‘startColor(‘+startColor+’)’, ‘input’);
feedback(‘targetColor(‘+targetColor+’)’, ‘input’);
feedback(‘id: ‘+id, ‘input’);

if(!steps) {
var steps = 25; feedback(‘steps: ‘+steps, ‘default’);
} else { this.steps = steps; feedback(‘steps: ‘+steps, ‘input’);
}

if(!time) {
var time = 28; feedback(‘time: ‘+time, ‘default’);
} else { this.time = waitTime; feedback(‘time: ‘+time, ‘input’);
}

var step = stepping();

feedback(‘step(‘+step+’)’, ‘proz’);

function stepping () {

feedback(‘fadingVectorObject.stepping ()’, ‘innerFunc’);

var diff = new Array (0,0,0);
var s = new Array (0,0,0);

for (var i=0; i < diff.length; i++) {
diff[i] = Math.abs(startColor[i]-targetColor[i]);
s[i] = diff[i] / steps;
}

return s;
}

var outputColor = new Array(0,0,0);
var betweenColor = startColor;

function nextStep () {

feedback(‘fadingVectorObject.nextStep ()’, ‘funcfunc’);

for(var i=0; i < startColor.length; i++) {
betweenColor[i] = betweenColor[i] + step[i];
outputColor[i] = Math.round(betweenColor[i]);
}
}

this.tween = function () {

feedback(‘fadingVectorObject.tween ()’, ‘func’);

s = steps;

nextStep();

dokument.getElementbyId(id).style.color = ‘rgb(‘+outputColor+’ )’;

feedback(‘tween() outputColor: ‘+’rgb(‘+outputColor+’ ) steps left:’+s, ‘ctrl’);

if (s != 0) {
s = s-1;
setTimeout(‘tween()’, 30);
}
}
}

function feedback(strMsg, format) {
var t = document.getElementById(“feedback”);
switch (format) {
case ‘func’:
t.innerHTML = t.innerHTML +
‘<h3 style=”color: green; color: green”>Call of function: ‘ +
‘<span style=”color:#50B450″>’ + strMsg + ‘</span></h3>’;
break;
case ‘funcfunc’:
t.innerHTML = t.innerHTML +
‘<h3 style=”color: green; padding-left: 0.8em; margin-top:1.6em ; color: green”>Function calls function: ‘ +
‘<span style=”color:#50B450″>’ + strMsg + ‘</span></h3>’;
break;

case ‘obj’:
t.innerHTML = t.innerHTML +
‘<h3 style=”color: green; color: green”>New Object: ‘ +
‘<span style=”color:#50B450″>’ + strMsg + ‘</span></h3>’;
break;
case ‘innerFunc’:
t.innerHTML = t.innerHTML +
‘<h3 style=”color: green; padding-left: 0.8em; margin-top:1.6em ; color: green”>Object calls function: ‘ +
‘<span style=”color:#50B450″>’ + strMsg + ‘</span></h3>’;
break;
case ‘input’:
t.innerHTML = t.innerHTML +
‘<p style=”color: #0c710c; padding-left: 1em; margin-bottom: -0.2em”> Input: ‘ +
‘<span style=”color:#229f22″>’ + strMsg + ‘</span></p>’;
break;
case ‘default’:
t.innerHTML = t.innerHTML +
‘<p style=”color: #0c710c; padding-left: 1em; margin-bottom: -0.2em”> default: ‘ +
‘<span style=”color:#229f22″>’ + strMsg + ‘</span></p>’;
break;
case ‘fix’:
t.innerHTML = t.innerHTML +
‘<p style=”color: #0c710c; padding-left: 1em; margin-bottom: -0.2em”> fix: ‘ +
‘<span style=”color:#229f22″>’ + strMsg + ‘</span></p>’;
break;
case ‘output’:
t.innerHTML = t.innerHTML +
‘<p style=”color: green; padding-left: 1em; margin-bottom: -0.2em”> Input: ‘ +
‘<span style=”color:#50B450″>’ + strMsg + ‘</span></p>’;
break;
case ‘proz’:
t.innerHTML = t.innerHTML +
‘<p style=”color: green; padding-left: 1em; margin-bottom: -0.2em”>prozessed: ‘ +
‘<span style=”color:#50B450″>’ + strMsg + ‘</span></p>’;
break;
case ‘ctrl’:
t.innerHTML = t.innerHTML +
‘<p style=”color: green; font-size: 0.8em; padding-left: 1em; margin-top: 2em; margin-bottom: -1.5em”>prozess control: ‘ +
‘<span style=”color:#50B450″>’ + strMsg + ‘</span></p>’;
break;

}
}

</script>
</head>

<body>
<h1 id=”toFade”>Uh Oh I’m fading… NOOOOOOOOO</h1>
<h2 id=”button”>Fade into nothing. Now!</h2>
<div id=”feedback”></div>
</body>

</html>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Mr_MooSep 05.2007 — I had a quick look at your code, so this may not solve all your problems, but with prototype.js you can bind functions to an object (which becomes the this). So what you want change is the setTimeout call:
<i>
</i>setTimeout(this.tween.bind(this), 30);
Copy linkTweet thisAlerts:
@jens1701authorSep 05.2007 — Hi Mr Moo,

thank you, your line got it to work! ?

Can you please explain the line. I don't fully understand it.

Greets

Jens
×

Success!

Help @jens1701 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...