PDA

View Full Version : Is it mandatory to know OOP and class stuff to create a component???


CyanBlue
06-02-2003, 05:06 AM
Howdy... ;)

Day 1 of learning how to create a component... Yay...
Got stuck with the problem in two hours already... Nay... :(

Aside from that problem, I have a question...
I am following 'Creating a Flash MX Component (http://www.flashcomponents.net/tutorials/triangle/triangle.html)' tutorial from the FlashComponents.net...

The author is talking about class and the stuff in this tutorial... I know what he means by class and what his code is doing... Well... That's simple class that has two properties... What could be so hard, right??? But then, this came into my mind... Do I need to know what OOP is and how to program things in OOP style if I were to create a component??? I know that OOP is a good way of programming and all, but I am not so comfortable with it as a matter of fact... :D

So, the bottom line question... I have created a movieclip that has all the bells and whistles but it is programmed in procedual way... and now I want to convert it to the component...

How hard will it be to convert that movieclip to the component??? Or, is it just not possible without the class and the stuff???

retrotron
06-02-2003, 06:41 AM
I'll take a crack at this, though I don't use components much these days. I reckon it's very possible to make a component that's not designed as a class. Just a little quirky, that's all. If anyone can do it, it's CyanBlue!

As far as I can tell (someone correct me if I'm wrong), the reason you define a component as a class is because classes have a constructor function that meshes really nice with initializing the component movieclip.

In Flash 5, when you put a smartClip on the stage, you had to wait 1 frame before everything became initialized. That could be annoying, for sure. But in MX we have the #initclip and #endinitclip. Any code between these pragmas gets initialized before any other code, and all this happens before any frames pass. This works real nice to get the clip initialized and ready to go before the rest of the code and playhead starts its work (or at least at the same time).

Every class has a constructor function, a function which is executed as soon as an instance of the class is created. It is thus very convenient to place our #initclip as the first line of code in the constructor function and #endinitclip as the last line of code of the constructor function. Mighty convenient if you go with OOP, but if you don't, I don't see why it's not possible to use these initialization pragmas to accomplish the same kind of thing.

Also, components which are built with OOP design can make frequent use of "this", and that makes their portability very easy because you don't have to worry about the parent. If you don't have an object, then your parent references can get tricky (so I hear . . . ). Again, these are not problems CyanBlue can't handle. :)

All that is to say this: I think making a component a la OOP is just a matter of convenience because (1) the initialization pragmas fit so well in the constructor function and (2) OOP coding makes references so much easier because of the constant use of "this". I could be way off on this, though, so somebody else jump in if I'm speaking nonsense.

CyanBlue
06-02-2003, 11:16 PM
Hm... Thank you for the thorough explanation, retrotron... ;)

It sounds like you are telling me that I can still go with the procedural programming to create a component, yet you are softly forcing me to learn how to do the OOP... :D

Well... I have tried a couple of times to learn it long time ago, but it didn't go well... I am not so sure if I can do it again, but I'll try it again soon... ;)

Thank you... :D

Billy T
06-02-2003, 11:51 PM
its not that hard to do basic OOP...why don't you download some files from the components section and just see how they are constructed...could copy/paste most of the class code

cyan - if you pay for the postage there and back I'd be happy to lend you my "OOP with Actionscript" book. Mort had a copy and I'm sure he would have lent it to you too, but unfortunately he did wee wee on his

cheers

senocular
06-03-2003, 12:15 AM
you really only need a base understanding of the OOP used in the component format. For most components, theres a pretty basic structure which is more or less the same for each and they are pretty basic in terms of the extents of OOP and Flash (without making a too terribly complex component).

The best way to do it is by making the simplest component possible to start. Most of the tutorials Ive seen dont do this, but its good to see components at their lowest, where their concept is most apparent; what they are and what they are supposed to provide you. Then, with that understanding, you can expand on things and get a little deeper into what a component can do and more into the OOP involved - that which makes the component more robust, more functional, and easier to use.

retrotron had some good points and Billy T is right about the OOP not being hard to do. You probably know enough now to be fine with it ;)

retrotron
06-03-2003, 12:22 AM
softly forcing me to learn how to do the OOPha ha . . . nah, I respect the procedural methods, I still do PHP that way. :) Besides, I think there's a good literature base out there that presents some really good reasons for staying away from OOP . . . I haven't looked into that, but it certainly perks my philosopher's curiosity bone.

On top of the OOP w/AS text, there's Robin's classic intro (though this one's Flash 5 style, but still does the job): http://www.debreuil.com/docs/

I'm still not entirely sure that one has to make components with OOP, I still think its possible to do it procedurally.

senocular
06-03-2003, 01:17 AM
I think it really depends on the component... was there something you had in mind that brought about the question?

CyanBlue
06-04-2003, 02:37 AM
Geez... Am I glad to see the site back up online??? ;)

Well... Billy T, what about you send me the book on the way to the US with all those crock's??? Don't you have enough crocks to sell already??? :D

Um... Let me get this straight... OOP... Well... Ever since I saw the pointer in C++, I hated it and I had fear on it... and that fear came back again when I started to learn what the heck is OOP... So, it is just like I really hate it and my brain doesn't and can't support that much, period... ;(

I have tried numerous times to learn it, and it happened to be the failure everytime I tried... (Which kinda supports my theory of lacking brain fuel and such...) So, I know bits and tits about the OOP, but not whole lot to go on and program with it...

Having said that, the reason why I have asked if I can create a component without the OOP is because all the codes that I have seen in the components are OOP and there was nothing I could even try to mimick what was going on in the files... and the fear of the OOP came up onto my head again... That's why... :(

Well... I thought that I'd learn how to create a component just to broaden my experience... Nothing more, nothing less... Yeah... As I was saying, I guess I'll have to start with simple things and see how it goes... I have been tingling with something for the last couple days while the site was down... and I guess I'll ask you guys for help on what I did... So... I'll keep my finger crossed and pray for this thing to be done, not one of thousands incompletes I have stashed somewhere... ;)

retrotron
06-04-2003, 03:10 AM
If anybody can do it, it's CyanBlue!

CyanBlue
06-04-2003, 08:47 PM
Um... Okay... Just to show you I wasn't really goofing around while the server was down... ;)

This is the scroller that I was working... I was meaning to create my own scroller, but I ended up using FScrollPane to do the scrolling part... (This also shows that I am lazy...)
Anyhow, what I wanted to do was to create a class that does accept data from the user that include text content, image file name, alignment and such to display it accordingly within the scroller...

I still need to check several things to make sure things are working right, but I can show you two paragraphs with the image in the left and the right...

I started to mimic OOP in the beginning, and ended up with pretty much procedural code after all... Can't do nothing about it... :D

Tell me what you think, and tell me I can use this one to convert to the component... ;)

http://www.cfhosting.it/CyanBlue/Tests/iScroller/iScroll05.html

bit-101
06-06-2003, 07:52 PM
your question has probably been answered, but here's my take:

to make a simple component that works, you don't really need to know much more than #initclip/#endinitclip and how to pass parameters from the parameters panel to the component itself.

the more you know about oop, though, the more features, flexibility, etc. you can add.

retrotron
06-06-2003, 08:32 PM
There you go CyanBlue, coming from bit-101 himself. :)

CyanBlue
06-06-2003, 08:53 PM
Yeah... Thanks for the answer, bit-101... ;)

Now, the question is how to learn OOP... Arg...

I'll get there sooner or later...

More likely later, long time to learn and get things goin... :(

Oh, well... This proves that teaching an old dog a trick isn't that easy... :p

bit-101
06-06-2003, 08:59 PM
the debruel tutorial mentioned a while back is good.

as for books, the flash oop bible is the sam wan/branden hall oop in flash book. it's great, but i'm not sure if i'd recommend it for someone just starting out. a bit too fast.

there is the william drol book. as far as i'm concerned, a bit too slow.

then there is the robert penner book. just right. :D

senocular
06-06-2003, 09:20 PM
Im working on a little OOP kick start for Flash, I'll let you know when its done CyanBlue ;)

retrotron
06-06-2003, 09:27 PM
Yeah, I love the Penner text too. One of the only Flash books I've paid for and not returned. ;) And an OOP from senocular would no doubt be excellent.

CyanBlue
06-06-2003, 09:29 PM
Yeah... Much appreciated, guys... :)

It's like... hm... I THINK I know what OOP is what is required to program something in OOP ways... The thing is that I am not comfortable with that way... Know what I mean??? It's like a phobia for me... Let's put it that way... :( It's like... um... yeah... I know how to drive a car, and I probably know how to fly an airplane since I have gone through a couple of courses... But the thing is that I am not comfortable with it... I probably can tell somebody who's on the chair what he/she should do, but I can't do it myself... Don't know if it was a good example or not, but that's where I am standing... :(

I hope this time will be a good starting point for my learning OOP try, um, #6, or something??? :p

Thanks guys... :)

bit-101
06-06-2003, 09:41 PM
it's funny, every oop book or article i've ever read talks about how it makes programming so much easier, simpler, intuitive, and then goes into these complicated explanations that make your head spin.

but, finally, after getting into more and more complex projects, i have started to see the truth of it. when you start seeing yourself doing the same set of actions to the same set of data over and over, you start to say, ahhh....that data should be packaged up with those functions. they'd make a nice object.

then you work out the methods for that object, and after a while you can stop thinking about the internal details and just deal with it as an object with methods. and you start looking at the bigger picture.

it's pretty cool, but it does take a while. it's one of those things that comes totally natural after you've practiced it for a long time. how's that for an oxymoron? :D

CyanBlue
06-06-2003, 09:49 PM
Alrighty... Thanks for the encouragement... :)

Just keep your fingers crossed so that I can pull it this time... :D

Thankie!!!

subquark
06-06-2003, 10:03 PM
yeah, more OOP! This is a great topic. Someone like myself has very little programming experience (FORTRAN in 1982 and ObjectPAL in 1994). I find that it is not the specifics but rather the approach to a problem. If I don't know that the book is behind me, then I don't know where the index is. Poor analogy but it is often the approach that snafus me. Once I "discover" (ie, CyanBlue writes the code) then I cann use my reference books to try and solve the issue at hand.

Thanks everyone on this forum!

retrotron
06-06-2003, 10:07 PM
subquark, where'd that quote about using WINE come from?

CyanBlue
06-06-2003, 10:15 PM
Haven't read it, but I guess this was the thread...
http://www.actionscript.org/forums/showthread.php3?s=&threadid=29001

retrotron
06-06-2003, 11:17 PM
Thanks bro, that's definitely it. Flash and linux . . . . mmmm

subquark
06-07-2003, 02:06 PM
:D