Math code?

Hi everyone,

I just purchased Robert Penner’s book and I was looking at part of his explanation of “static objects”. He implements his own Math function, the code is:
[AS]Math.cube = function (x){
return xxx;
}
trace(Math.cube(20));[/AS] According to Mr.Penner, the trace function will give 8000, however, when I entered this in the actions window the output is two error messages. I am using Flash MX 2004. I was wondering why this is happening, and if anyone could help me clear this up.

Thanks A Lot
:cap:

Well, if you do like this:

[AS]
cube = function (x){
return xxx;
}
trace(cube(20));
[/AS]

…you won’t get errors.
I guess that using Math requires a pre-defined function such as round().
I haven’t worked a lot with the math-funcion (not at all :wink: ), so I’m simply guessing here…

Maybe someone else can fill in the gaps for me… :slight_smile:

Yes Math is a pre defined function and cube I guess is not one of its subs

That used to be obtainable in MX, but MX2k4 made bulit in class no editable. So you cannot add functions to any built in classes in MX2k4. In other words, only user defined classes are dynamic.

*Originally posted by norie *
**That used to be obtainable in MX, but MX2k4 made bulit in class no editable. So you cannot add functions to any built in classes in MX2k4. In other words, only user defined classes are dynamic. **

I’m not sure on this, but I think the MovieClip class and perhaps a few others are dynamic.

I would have thought that if they weren’t dynamic then you wouldn’t even be able to go

myclip.bla = "val";

yes, you can do that, but can you do this:

MovieClip.bla = "val";

MovieClip is the class

and myclip is an object of the class.

you should be able to with MovieClip. As njs said, MovieClip is dynamic (and a few others - I dont know offhand but Math is NOT one of them). This adds to AS 2.0’s improved debugging and ‘control’ though really it takes away your control in the idea that you wont screw yourself over with what you intend to do, like messing with Math object functions. IMO, it sucks, which is why I stick to AS 1.0. Unless your object is Dynamic, you cant just make functions like cube on the fly like that - at least not for AS 2.

If you’re not using external class files with your project in MX 2004, Id suggest opening up the preferences and using AS 1. You’ll have much less problems with it and things will work better for you.

see, i was close, kinda :beam: