----------------------------------- ftm Mon Jul 21, 2003 1:42 pm Intro to OOP in Flash ----------------------------------- First, i'm not a master, but i've learnt quite a bit from the book "Object-Oriented Progamming with Action Script" by Branden Hall and Samuel Wan. I guess my hope is to give you a little bit of what they gave me. But if you can PICK UP a copy of the book i would recommend it. Flash is a lot different then C, Java, or Turing. In terms of syntax it is quite similar to C and Java but the language is a lot more flexible and 'forgiving'. But i'm supposed to be writing about OOP in flash so here we go. Flash is a prototype language. This means that rather than use a class, you create a function, that can be duplicated. Basically. Let's look at some syntax so i can confuse you more: function foo (parameters){ ... } variable = new foo (); so what happens here is that you've created this function 'foo', and instantiated it in the variable 'variable'. So rather than be a class and having pointers all you've done is declared this variable a new foo() ... which is what i meant by duplicating. It's like you've basically taken your general function and made a copy with specific parameters. It's not a class that's the point. and right now that doesn't prove to be any more powerful but just wait. so the next thing is how do you put in variables and functions? here you go: function Foo (){ this.var1 = whatever; this.function1 = function() { doSomething; }; } OR function Foo(){ this.var1 = whatever; } Foo.prototype.function1 = function () { doSomething; }; So there are the basics. Play with that. Here's something to think about though : Remember how i said Flash was forgiving? You can reference to functions that don't exist with out flash crashing out. But once you create a function with that name, it will be called and run. And remember you dont have to make all your objects functions when you first make the object. You can use the line Foo.prototype.function1 = function(){}; anytime you want! You can also add new functions to specific instances of your object. like so instObj = new Foo(); instObj.newFunc = function (){ doSomething; }; So go play... and final note, apparently inheritance in flash is shit and/or doesn't work at all... i really suggest that book, OOP with action script, i'm sure any fine local retailer will have it... i got mine at this small little store... i think it was called kazaa... or i could be wrong and it was coles... yeah coles that works.... p.s. i know i'm terrible at explaining shit so ask any questions or call me an an idiot i've been told many times i cant explain things for shit... ----------------------------------- rizzix Tue Jul 22, 2003 1:12 am ----------------------------------- oh thats good news Flash is OO hmm actually it reminds me of JavaScript.. not really Java or C ----------------------------------- krishon Sun Jul 27, 2003 4:59 pm ----------------------------------- flash always has been OO......well since i've used it :D