Newbie Function problem

I am quite new too all this flash stuff, and just got a book on Flash Actionscripting.

When i type in the following source code, the book says that the message “Hi there!” should appear in my output box, which it doesnt.

function sayHi () {
trace(“Hi there!”);
}

What is it im doing wrong??

Cheers

sowry got another one here:

I have created a movie clip with a round ball and on the main timeline i have inserted this:

_global.mainTimeline = this;

function moveBall () {
mainTimeline.ball._x += 10;
mainTimeline.ball._y += 10;
}

moveBall();

the ball is apperently supposed ta move, but it aint.

please help,

cheers

I think you’re going to need to define the main timeline in the function, but then again, I don’t see any reason to use that instead of a this, it’s more that trible the length

try:

function moveBall () {
_global.mainTimeline.ball._x += 10;
_global.mainTimeline.ball._y += 10;
}

Adam

to get motion, you have to call the function from the mc, so add this code to your mc:

moveBall();

and take off moveBall() after the function definition on the frame.

cheers

First you should use _global whenever accesing that global variable.
And the ball will move but will move only once since the function is called only one time.

ah, one more thing: on your mc, add:

onClipEvent(enterFrame) {
moveBall();
}

b/c you have to have a clipevent for mc… sorry i forgot

which is why it’s good to have that on the mc, b/c it calls that function at whatever frame rate your movie is, over and over until you stop it.

I’d recommend using dynamic event handlers so you can erase it whenver it is not needed anymore.
Something like:

_global.mainTimeline = this;
function moveBall() {
	_global.mainTimeline.ball._x += 10;
	_global.mainTimeline.ball._y += 10;
}
onEnterFrame = moveBall;//will execute the function at the frame rate of the movie

really? i didnt know that you could attach onEnterFrame to a frame w/ the same effect… tries

wow… i didn’t know that! thanks for enlightening me, claudio :smiley:

well, that pretty much sums it up pretty well, I was trying to make it easy and give a short answer, oh well

Anytime bodyvisual :slight_smile:

i can get claudios last post ta work, but none of the others.

I have posted up my .fla if someone can please have a look at it, alltho claudios worked…i want to follow the book.

cheers