Topic: Flash code planning (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=11462" title="Pages that link to Topic: Flash code planning (Page 1 of 1)" rel="nofollow" >Topic: Flash code planning <span class="small">(Page 1 of 1)</span>\

 
Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-13-2003 23:42

Almost all the ActionScript examples I see involve making a bunch of frames and nested movie clips, each with their own relatively small sets of actions. I hate this approach, because it looks way too easy to get lost in. Is it wrong of me to want to write a few master classes and use them to control the entire application? And, well, is it possible? It looks like Flash really wants me to use a ton of keyframes, movie-clip objects, nested movie clips each with their own timeline, and so forth, all with their own ActionScripts. Sounds like a headache.

Cell 1250 :: alanmacdougall.com :: Illustrator tips

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-14-2003 03:28

You should be able to accomplish most things without needing to resort to numerous timeline scripts. Few of the tutorials I've found for flash are actually useful in a real application. Most of them are simply exploiting the ability to script within a timeline like environment to accomplish some cheap effect.

That being said, Steve wrote a nice primer about where action script code goes and why over at the GN, I suggest you read it if you haven't done so already.

Although, there will always be times when you'll need to do that. That?s just how flash is. However, there are many ways you can simplify things.

For example, I usually make heavy use of the ability to attach movie clip instances from the library, which gives you the ability to code the application as a series of components (no, not the awkward flash "components" per say, I'm using the word in a more general sense, although I hear they're easier to develop in MX 2004).

For example, say you have a custom alert box component, you could attach it then setup button events like so:

depthN = 10
initObj = [type:"error", _x:100, _y:100]

targetMC.attachMovie("linkageID","myAttachedMovie",depthN,initObj) // you'll want to check the syntax for this one...

targetMC.myAttachedMC.controlsMC.closeButtonMC.onRelease = function() {
Close alert box code....
_parent._parent.removeMovieClip() // not to sure that address is correct, might need another _parent but you get the idea...
}

And so forth. It can get a little long winded and it's still a bit of a pain trying to keep track of where everything resides as you dynamically attach things left right and centre, but it's no where near as confusing as having a mess of code throughout the movie.

You can also make movie clip object instances children of custom code objects, which can also remove the need to have many scripts inside movie clips. Although, I've not played with this terribly much yet, but it does have it's uses here and there.

Also note that with flash MX 2004, if you use classes then I believe you have to use external action script files, which should help you avoid this problem anyways.

At the end of the day, it all depends on what you're trying to do. If you need to script timeline events and you don't want to go out of your way to create a scheduler to control all the animations you require, then you'll most likely need to use timeline/frame scripts here and there. However, if you do not need to script any time based actions, then you shouldn't be using frame scripts.

Although, I've only been using flash for a few months, and only developed one not so usefull applicaiton with it, so I'm sure there are a lot of other ways to help keep it all togther, but their the ways I've found that seem to be working quite well.

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-14-2003 03:52

Well, there are a few things I need to do with Flash right now, and a few ways I want to do it.

I need to get an XML file from my PHP backend and traverse it item by item (the game is a quiz, and the XML contains all the questions and answers pre-generated). I've got a firm grip on this.

I want to animate a game GUI with all the whooshing and whizzing graphics that make Flash so Flashy. This includes fancy transitions from question to question to bonus round and so forth, as well as visual feedback on answers.

I want to be able to create almost all of this using external ActionScripts, mainly so that I can use JEdit instead of Flash's less-capable built-in editor. And I want to keep the number of external ActionScripts down, presumably by using powerful classes with lots of relevant methods. I stopped studying Java in order to learn Flash from the ground up -- imagine my surprise when I found that nearly everything I'd learned is applicable.

I want most, if not all, of the animations to be scripted rather than keyframed and tweened and whatnot. I really don't like Flash's authoring environment, so if I can put in a little extra work just to avoid it (and make things more flexible in the process), I will.

Oh, and of course I'm doing all the artwork in Illustrator. Goes without saying, I think. After years of Illustrator, Flash's vector tools feel alien and somewhat slimy.

I'll look around Steve's tutorial -- he always comes through with the goods. And I'll check the FAQ for some more relevant resources. Can you suggest any other sites that'll help me on my goal of ActionScript-only Flash development?

Cell 1250 :: alanmacdougall.com :: Illustrator tips

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-14-2003 03:54

Argh - you slipped in a post while I was typing htis epic. Well, hope it helps anyway.

BTW - don't bother with my code tutorial. It made sense in Flash 5, but it's very very wrong for MX practices.

PT: I think it REALLY depends so much on what you want to do. The things I've done recently that I'm proud of (the GN chat, my rss reader and gallery for example) are almost entirely code. The classes and methods go on for pages; the main timeline is just about 1 frame long (though several layers "high" for organization). But these might not be examples of anything that appeals to you.

There seem to be two schools of thought: the timeline branch and the ActionScript branch. I gravitate to the latter, but honestly, Flash IS a timeline-based paradigm and I think maybe there is some middle ground that exploits the best of both approaches. Jared Tarbell has done some extremely clever things using both timeline tweens and very advanced code.

Maybe you've been hanging out at all the wrong sites! Some of the most exciting code-related info today is appearing in the form of blogs. Treat yourself to one wild man: eric dolecki and start methodically trolling through his links (left column). You'll be blown away. I've been following Grant Skinner's blog for instance - a TON of very cool info about FlashMX 2004. Also, since you are clearly into OOP, check out Joey Lott's three outstanding introductory articles. And don't overlook Sam Wan, Branden Hall or Robert Penner (famous for his movement classes, in ActionScript 1 and recently updated for ActionScript 2 here.) And then there's the FlashCoder's Mailing List if you have the endurance!!

It's a big world, and Flash accommodates all sorts of developers. If you yearn for OOP practices, you don't have to look too far to find more than you could ever digest.


[This message has been edited by Steve (edited 10-14-2003).]

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-14-2003 04:02

"I stopped studying Java in order to learn Flash from the ground up -- imagine my surprise when I found that nearly everything I'd learned is applicable"

That was immediately evident to me in that code fragment in your other thread. "private" methods were the give away!

If you have a Java background, you're ahead of the game.

I would REALLY recommend you get a good book. Moock's ActionScript for Flash MX is in my opinion the best available. Particularly for one with a Java background: Moock takes pains to point out where ActionScript and Java part ways. Private methods are a good example. Flash doesn't have private methods, at least not MX. You can WRITE a private method, but more as a reminder to yourself not to access it directly. You have to pretend it's private!

As far as doing "Flashy things" with code: take a look at Penners demo. All code, and very flexible. ActionScript is what is taking Flash beyond mere animation into truly interactive realms.

Your quiz sounds neat. Get Moock's book - he uses a quiz as an example throughout his book, adding features and complexity as he goes.

[This message has been edited by Steve (edited 10-14-2003).]

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-14-2003 04:25

"I want to be able to create almost all of this using external ActionScripts, mainly so that I can use JEdit instead of Flash's less-capable built-in editor"

2 thoughts on that:

Positive: I've heard good things about JEdit, but the REAL reason to write external .as files, especially when you start getting big classes, is how easy it makes it to use them in different projects. I keep going back to Penner's motion classes. You invest time in writing a big, flexible class like that, you want to be able to use it more than once! External files make that a snap. And, as Dracusis points out, Flash MX 2004 is going to enforce that discipline on you.

Negative: it may be more capable, but you do lose the advantage of Flash's syntax checking and code hinting. I LOVE both of those features!

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-14-2003 04:45

Steve: I was editing one of my external actionscript files at university the other day and it automatically opened in dreamwerver -- to my surprise dreamweaver actually included all the same code hinting stuff as the flash authoring environment.

I'll be looking around for a good actionscript book some time in the next month or two to keep me busy over the summer holidays comming up, know of any good MX 2004 books I should look out for?...

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-14-2003 05:14

macromedia is publishing one called "M.M. Flash 2004 Demystified", but it hasn't been released yet. It's the only title I've heard about so far, and that only because Grant Skinner mentioned in his blog that he had contributed a chapter.

More will be coming soon I'm sure!

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-14-2003 09:07

Steve -- very helpful information! I'll be sure to read as much as I can from those links, and if I can scrape together the spare cash I might pick up Moock's book.

Cell 1250 :: alanmacdougall.com :: Illustrator tips

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-15-2003 00:22

Holy cripes! Penner's movement classes are exactly what I was trying to figure out when I posted this thread! I'm going to analyze his code like my name was Zero Cool.

Cell 1250 :: alanmacdougall.com :: Illustrator tips

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-15-2003 02:24


Thought that might be a 'fit'


But, uh, dude - HIS name should be Zero Cool!

See if you can find anyone who has Penner's book, willing to lend it to you. There is a LOT of stuff in it that might be of immediate use to you, but it's more narrowly focused than Moock's. Spend money on Moock; try to beg borrow or steal Penner's. Moock's book is broader and will stand you in good stead no matter what you do in ActionScript. Penner goes into more detail and depth in a smaller area of specialization.

I'll say one thing - I've written to Colin (Moock) more than once with questions and he has always answered. I wrote once to Penner with a suggestion for making some crucial bit of code more obvious and got silence.

If you get a copy of Penner's book, be SURE to download the example files from the web. His book completely omits a key routine which is an #include file in his online code files.

(A hint: the online files include a dynamically created movie clip that broadcasts an enterFrame, without which you're out of luck!!!!)

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-15-2003 05:48

I've trawled mooks blog from end to end as was considering buying his book, but since MX 2004 is out, I think I'd really prefer to get an MX 2004 book as they've changed quote a lot actionscript wise.

ps. I menationed in here a while back that Macromedia would most like be dumping Director, I recently discoverd that's not so, Director MX 2004 (Director version 10) is currently under development and a release date is pending. Yay!

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-15-2003 05:55

Well, Moock's book is now in edition 2, which I think covers MX 2004 (??) -- anyway, I'm getting a friend to buy it for me as payment for some Flash work I'm going to help him with.

edit: No, guess it doesn't. Well, I'll just use the book and pay attention to all the "what's new in MX 2004" articles to set me straight on the differences.

Cell 1250 :: alanmacdougall.com :: Illustrator tips

[This message has been edited by Perfect Thunder (edited 10-15-2003).]

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-15-2003 12:48

I don't have first hand experience w/ 2004, but my understanding is that the only significant change is with writing classes. Of course I realize that's a huge deal for PT, but still - the book will be useful in many ways for quite some time, because there's a lot more to AS than classes.

Also - MX had been out for quite a while before Moock's version 2 was released. (When you get it and marvel at its depth you'll appreciate why.) So - if you want to be learning ActionScript now, I wouldn't wait for version 3 - could be some time yet!

Amazon might have used copies??

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-16-2003 00:17

If it's just classes, I'll be fine; I've got enough experience on both sides of the procedural-vs.-OO fence that I can easily make the switch from one to another. And I've just figured out how to "assign orders" to objects using events and listeners (the old onEnterFrame loop), so I think I'll be able to muddle my way through for now.

Cell 1250 :: alanmacdougall.com :: Illustrator tips

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-16-2003 00:47

onEnterFrame is good, and reliable. Weadah still prefers it last I heard. The sneaky thing Penner does that I wrote to him about it to create (dynamically) an empty movie clip whose primary reason for existence is to broadcast onEnterFrame events to custom objects that aren't movie clips and thus don't generate that event on their own.

But you might want to investigate setInterval. Mighty cool. You can call a function every however many milliseconds you want, not tied to the movie's frame rate.

I forgot in our earlier discussion to point you to two of Grant Skinner's resources. First, the Flash interface to his previous site (version 3 is evidently coming - can't wait to see what that's like). When you talked about wanting to do "Flashy" things in flash using code - this came to mind immediately.

Second, his gModeler, a free, online "UML modeler and documentation tool" which is beyond me, but might be of real help to a Class writer with a stronger OOP background than mine.

enjoy!


[This message has been edited by Steve (edited 10-16-2003).]

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-16-2003 07:24

Ah, very interesting -- I'd been meaning to learn some UML, although so far I haven't embarked on a project large enough to require it. I definitely have a habit of writing pages of notes and planning (longhand) -- it helps organize my mind.

I'll look into setInterval; I played with it a bit before, but didn't have quite enough background to get it to work. Now I think I do. At this very moment I'm doing that work for my friend, and I'm meditating on depth... I want to be able to dynamically populate the stage using library elements. MovieClip.attachMovie() does this admirably, but the required depth argument looks like it could cause problems. Right now, I'm setting a depth_index variable that increments each time I place a new object... but is there a way to get the highest depth of all objects (sort of a "paste in front"), or even better, to separate objects into arbitrary "layers" programmatically? I understand that I can create a blank movie clip to act as a layer-like container, and then load movie clips into that one, but I'm wondering if there's a better way.

Anyway, this is just idle curiosity, on the off chance that someone feels like answering; I seem to have a firm enough grip that I can do this on my own. My first two attempts to learn Flash were disastrous, because I got caught up in unfamiliar and confusing keyframes and separate frame/object/button actions... but approaching it from a pure code perspective it's proving to be as easy as pie.

edit: I read Penner's article on broadcast events and custom event sources, and I'm sure I can make use of them somewhere along the line. Good stuff, that man has.

[This message has been edited by Perfect Thunder (edited 10-16-2003).]

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-16-2003 08:45

Alrighty then, I'll swing by the bookshop next week and pick up a copy of Mook's book. Truth be told I probably won't be able to get my hands on Flash MX 2004 for a while yet, my university is quite slack when it comes to upgrading the software in the design labs and the entire creative industries factuality (sp?) is moving to a series of new buildings over x-mas, so it could be march 2004 by the time I get my hands on it.

And thanks for the link to gModeler, and all the other super helpfull stuff you've posted in here. I've been leaning a lot about UML lately (not by choice, their making me learn it at uni, but it is good for planning and documentation) might come in handy for some of the projects I'm planning on building over the next six months though. If only I wasn't so busy right now, so much to read and learn, so little time...

PT: My first couple of experiences with flash sound extreamly similar to yours. =). I fact, not 12 months ago I was one of those people hanging out in the "hate all things macromedia" camp. Today I rarely work in anything but Director or Flash, hah.

Oh and let me know how you end up tackeling that depth issue, I've had similar issues with that before and never really found a nice and clean solution.

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-16-2003 09:54

Well, I haven't quite tried it yet, but I R'ed TFM, and what do you know? MovieClip.getNextHighestDepth() looks like exactly what I needed. Brand new for MX 2004, and not a moment too soon (although it doesn't help in this one, since I'm targetting vanilla Flash MX).

Cell 1250 :: alanmacdougall.com :: Illustrator tips

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-16-2003 15:39

"MovieClip.getNextHighestDepth()"

~swoons~

For now, maybe a _global variable "depth", and then ++depth for each attached clip?

I'll think about this one a bit. Seem to almost remember reading something about it, but where and what escapes me at the moment.

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-16-2003 22:22

courtesy Joey Lott, from his "ActionScript Cookbook" (O'Reilly):

code:
MovieClip.prototype.getNewDepth = function () {
//if no currentDepth is defined, initialize it to 1.
if (this.currentDepth == undefined) {
this.currentDepth = 1;
}
//Return the new depth and increment it by 1 for the next time
return this.currentDepth++;
};



usage (he creates a movie clip dynamically for his example, but just swap the attachMovie syntax for your project):

code:
_root.createEmptyMovieClip("circle_mc", _root.getNewDepth());
_root.createEmptyMovieClip("square_mc", _root.getNewDepth());





[This message has been edited by Steve (edited 10-16-2003).]

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-16-2003 23:04

So MovieClip.prototype has properties that are global to all MovieClip objects, huh? Oh, and the "global depth++" thing is what I'm using right now. Works okay.

Cell 1250 :: alanmacdougall.com :: Illustrator tips

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 10-17-2003 00:38

Yeah, I knew I left that out. Sorry. From what I read, the single biggest thing a Java programmer has to understand about Flash MX OOP is that, like JavaScript, Flash is a prototype based language, NOT a class based language. 2004 may be different, as it now contains an actual "Class" statement.

Lott's custom method getNewDepth() extends the MovieClip prototype, and thus any new movie clip inherits the new method. You can extend any of the built in classes by addressing its prototype, Math for example (lots of Penner examples available). You can just as easily extend a custom class, and you can even assign a custom class to inherit from another in its constructor (although beyond this inheritance gets quite technical):

code:
MyShape.prototype = new MovieClip();


and prototype can be used to add methods to a custom class:

code:
MyShape.prototype.getArea = function {
//insert code for the method
};



layer 51 has an extensive collection of prototypes you might want to study.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu