# Math code?

**URL:** <https://forum.kirupa.com/t/math-code/38577>\
**Category:** Uncategorized\
**Created:** [December 25, 2003, 10:12pm UTC](https://forum.kirupa.com/t/math-code/38577 "2003-12-25T22:12:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceman](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@iceman](https://forum.kirupa.com/u/iceman)\
**Post date:** [December 25, 2003, 10:12pm UTC](https://forum.kirupa.com/t/math-code/38577/1 "2003-12-25T22:12:23Z")

</div>

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 x_x_x;  
}  
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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 25, 2003, 10:25pm UTC](https://forum.kirupa.com/t/math-code/38577/2 "2003-12-25T22:25:25Z")

</div>

Well, if you do like this:

[AS]  
cube = function (x){  
return x_x_x;  
}  
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 😉 ), so I’m simply guessing here…

Maybe someone else can fill in the gaps for me… 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 25, 2003, 11:10pm UTC](https://forum.kirupa.com/t/math-code/38577/3 "2003-12-25T23:10:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 25, 2003, 11:21pm UTC](https://forum.kirupa.com/t/math-code/38577/4 "2003-12-25T23:21:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 25, 2003, 11:27pm UTC](https://forum.kirupa.com/t/math-code/38577/5 "2003-12-25T23:27:11Z")

</div>

> \*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

```auto
myclip.bla = "val";

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 25, 2003, 11:33pm UTC](https://forum.kirupa.com/t/math-code/38577/6 "2003-12-25T23:33:37Z")

</div>

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

```auto
MovieClip.bla = "val";

```

MovieClip is the class

and myclip is an object of the class.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 26, 2003, 2:08am UTC](https://forum.kirupa.com/t/math-code/38577/7 "2003-12-26T02:08:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 26, 2003, 4:44am UTC](https://forum.kirupa.com/t/math-code/38577/8 "2003-12-26T04:44:59Z")

</div>

see, i was close, kinda :beam:
