Re: [Flashcoders] Dynamic class instantiation
Here is the class I use for dynamic instantiation. Note that it throws a custom exception type, you'll have to create that type yourself or alter that line of code. I copied the instantiation technique from Drew Cummins at blog.generalrelativity.org. class com.phoenixgp.common.utils.ClassLoader { /* CLASS METHODS */ /** Returns a new instance of a class given the fully-qualified name of the class. The instance will be returned as an Object, so the caller must cast the return value to the expected type or supertype. Original author: Drew Cummins, blog.generalrelativity.org @param classPath The fully-qualified class name, in dot notation @return A new instance of the named class, using its default constructor @throws ClassNotFoundException if the named class is not present. This may indicate an error or omission in the ClassRegistry. */ public static function createInstance(classPath:String):Object { var packageList:Array = classPath.split("."); var constructor:Function = Function(_global); while (packageList.length > 0) { constructor = constructor[String(packageList.shift())]; } if (constructor == null) { throw new ClassNotFoundException(classPath); return null; } return new constructor(); } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] books for flash programming
On 3/24/08, Naveen Bhaskar <[EMAIL PROTECTED]> wrote: Hi, I am a flash designer and I am in intermediate in programming.(AS2). anybody pls tellme what are the good books I can refer. And remember, just learning Actionscript in particular will not teach you programming in general. Jeff Atwood has an excellent list of books on topics essential to all programmers, even Actionscript programmers: http://www.codinghorror.com/blog/archives/20.html And if you really want to be a programmer, learn more than just Actionscript! A scripting language like Python, Ruby, or Perl will be extremely useful to you even as Flash developer -- but you'll never realize it until you've learned one. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] [cross-post] Expert contractor needed, green-field project, telecommuting, not a headhunter
Hello! I am not a headhunter, just a lone programmer whose shop needs more man-hours than I can generate. I'm posting this to Flashcoders, Flexcoders, and Flash_Tiger because I know there are more smart freelancers on these lists than on every craigslist in the world. My small interactive media company wants to build a fairly ambitious internal project -- a framework for building product configurators with potentially complex constraints. We'd be using AS3 and almost certainly Flex. Unfortunately, I'm the only programmer, and I'm up to my ears in deadline-intensive work. We hope to hire a contractor (consultant, freelancer) to collaborate with us on the design and handle 99% of the implementation. This is a framework we're going to have to live with for a long time, so we're eager to get it right. That's why we want to hire someone with better-than-average design and coding skills. Behold, our ideal contractor: * At least five years programming experience, and enough AS3/Flex experience to feel confident. I don't buy the "years of experience myth," but I do buy the value of _general_ programming experience. * Experience with, or at least eagerness to use, unit and functional testing. * Experience building/populating applications from XML declarations. (This is a classic Flash thing, so probably goes without saying.) * Enough object-oriented experience to know how to keep a design from exploding into a pattern souffle. * A clear and eloquent coding style. We love descriptive variable names and doc comments. * Ideally, framework experience: we want to generate mini-applications by binding external data into a Flex/AS3 scaffolding. * Domain-specific knowledge like boolean satisfiability or relationship graphing would be great, but not required. No restrictions on location, telecommuting is fine. I am NOT in charge of compensation, but it would be competitive, bearing in mind that it would be a moderately large project under minimal time pressure. Excellent English preferred. You'd be keeping in touch via email, IM, and phone, and performing regular checkins to our source control system for code reviews. Please respond to [EMAIL PROTECTED] Thank you! Alan MacDougall The Phoenix Group ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] DropShadowFilter rendering issue: SOLVED
Muzak wrote: AFAIK, both are "between 0 and 1". The default value for strength = 1, meaning 100% strength. If strength would take a value between 0 and 255 a default of 1 would make no sense at all (well at least not to me). Well, the docs are correct: you can set absurd strength values because some effects could be very weak. For instance, I've seen glow filters at 400% strength: 4.0. It just gives a really bright nimbus. The trouble is that the range of allowed values is misleading as to the values' effects. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] DropShadowFilter rendering issue: SOLVED
Hal Leonard wrote: Yeah in CS3 that's the case - regardless of whether you are using AS2 or AS3. But to my knowledge, in Flash 8, it is still 0 to 100. No, that was the problem: In the Flash 8 authoring environment, you set a 0-100 percentage. But in Actionscript 2.0, the DropShadowFilter.strength property has a range from 0 to 255, where each full integer represents 100% strength. Setting DropShadowFilter.strength = 255 would actually give it 25,500% strength. DropShadowFilter.strength = 0.5 would give it 50% strength. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] DropShadowFilter rendering issue: SOLVED
Alan MacDougall wrote: After I create a clip with attachMovieClip, I attempt to write a DropShadowFilter to it using the following code: var shadow:DropShadowFilter = new DropShadowFilter( 5,// distance 45,// angle 0x66,// color 75,// alpha 10,// blurX 10,// blurY 100// strength ); myClip.filters = new Array(shadow); Myth: the strength property of DropShadowFilter takes a value from 0 to 100. Fact: It's actually 0.0 to 1.0. I was trying to apply a 10,000% strength drop shadow. MYTH BUSTED. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] DropShadowFilter rendering issue
After I create a clip with attachMovieClip, I attempt to write a DropShadowFilter to it using the following code: var shadow:DropShadowFilter = new DropShadowFilter( 5,// distance 45,// angle 0x66,// color 75,// alpha 10,// blurX 10,// blurY 100// strength ); myClip.filters = new Array(shadow); Instead of a proper bitmap drop shadow, this is producing a solid gray area where the shadow gradient would normally appear. Any tips? Flash 8, targeting Flash 8. Authoring-time drop shadows have the same settings and work fine. I was originally doing this with FuseFMP, but tried the raw AS syntax to make sure it was a Flash issue. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Big size Image and Thumbnail
julian atienza wrote: but i'm not sure if it's going ok... at least now i haven't to make another load but... i think the thumbnail is scaling the portion of big image i see in screen, not the whole image... That might be a limitation of Flash. I'm not sure what happens when MovieClips and BitmapData are larger than the maximum movie size (which I think is 2600 pixels or so)... I would not be surprised if it messes up, though. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] long dash
natalia Vikhtinskaya wrote: Hi I thought it simple but that does not work.I am trying to show long dash c="a — b" txt.html=true; txt.htmlText=c; But that does not work. What am I doing wrong? Thanks in advance Flash actually only displays a few HTML entities: < > " & (I think) and one other that I forget. If you want to use any other special characters, use the code appropriate to your encoding style. In ASCII, for example, it's symbol 151, which you can enter in Windows with alt-0151. In Unicode, I think it's \u8212, but don't quote me. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Big size Image and Thumbnail
julian atienza wrote: Image is 72Mb. This is your first problem. I can't think of a single reason you would have to load a 72 MB image into Flash. Could you tell us a little more about your application? ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Big size Image and Thumbnail
Dave Mennenoh wrote: To avoid loading twice times the image (first in 100% and second in "thumbnail" navigation image) ... how could i copy content of first movieclip to second one with fixed size? You can't really, but since the image is cached once it's downloaded the first time, loading it again into the thumbnail will be nearly instant. Hah... I posted an overly-fancy BitmapData copying solution -- it hasn't gone through yet -- but Dave's answer is a lot better. If both versions of the image are static, just loadMovie them both. I originally did that BitmapData thing to display a magnified area of a complex clip generated from user input, but it's overkill for static images. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Big size Image and Thumbnail
julian atienza wrote: To avoid loading twice times the image (first in 100% and second in "thumbnail" navigation image) ... how could i copy content of first movieclip to second one with fixed size I did something similar to this while trying to implement my own Bitmap-based magnifying glass (following this example by Grant Skinner: http://www.gskinner.com/blog/archives/2005/09/flash_8_bluepri.html). You can use a single MovieClip as the source for as many individual bitmaps as you want, limited only by your CPU power. Look up the basics of attaching bitmaps and using BitmapData.draw -- that's all readily available in the manuals and tutorials. Then just create two bitmaps attached to two movieclips, and do this: // assume that source is the MovieClip containing the original image var matrix:Matrix; var normalScale:Number = 1.0; var thumbScale:Number = 0.25; // draw to the bitmap at the normal scale matrix = source.transform.matrix; matrix.scale(normalScale, normalScale); normalBitmap.draw(source, matrix); // draw to the bitmap at the thumbnail scale matrix = source.transform.matrix; matrix.scale(thumbScale, thumbScale); thumbBitmap.draw(source, matrix); Now the normalBitmap (a BitmapData object) has your image at full size, and thumbBitmap has the image at 1/4 size. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] "This is not Java": property accessors
And another point: Suppose you start out making something as a public field and then later realize you need to restrict its value in some way. With properties, this change will make absolutely no difference to the rest of your code. Without properties, you will have to change every instance of "obj.myField = x" to "obj.setMyField(x)" and every other instance of "obj.myField" to "obj.getMyField()". So it makes this type of refactoring far easier. Well, the idea is that you'd never mix the two syntaxes. Either every single field uses explicit getters, or every single one uses property-style access. Personally I find properties (i.e., implicit getters and setters) to be one of ActionScript's few advantages over Java as a language. (Now if only we could have abstract classes, exception types in function signatures, etc) An abstract class is just one that provides some of the implementation, but not all of it (as distinct from an interface, which provides none of the implementation). You can do abstract classes in AS, just name them "AbstractButton implements Button" and then "SpecificButton extends AbstractButton". This does require that all your coders know not to try to use an abstract-named class directly. It's not enforced by the language, but that's not a huge loss. The only reason to put an exception in a method signature is to ensure that it is checked, and I actually don't like checked exceptions. I would like to know about exceptions, but not be forced to handle them at compile-time -- that just leads to a lot of lazy "swallowed" exceptions, and in a really big app you could even be forced to handle exceptions that just aren't relevant to begin with, or for which you have no resolution context. And for simply informing the coder about exceptions, just include it in your documentation. AS2API allows a "@throws ExceptionClass when blah blah blah" comment, I'm sure ASDoc and other solutions do too. The things *I* miss most from Java are generics, and the ability to define constants in interfaces. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] "This is not Java": property accessors
Further derail! What are people's thoughts on implicit vs. explicit accessors? I prefer explicit ones, but I confess that it's almost entirely because I learned Java before Actionscript. You can't argue that explicit setters are required for a "serious" language, because C# prefers implicit setters. (For the sake of argument, let's just agree that C# is a serious object-oriented language.) From a practical standpoint, using myObject.property is perfectly effective. If it's a property that should be insulated from direct modification, you just apply a public implicit getter to a private field. If it's a property that need not be insulated, such as MovieClip._x, why not just make it public? As long as the naming and effects are consistent, I don't see a practical drawback. Theoretically, though, I like explicit setters because they make it very clear that you're calling methods which act on internal fields. myObject.getProperty() tells the coder "you're getting a value, but NOT necessarily the value of any particular internal field," while myObject.property implies that they're getting internal state from the object. (Another advantage, in Actionscript, is that using explicit setters reserves pure dot-notation for movieclip paths: foo.bar.baz must clearly be a MovieClip nesting, while foo.getBar().getBaz() must clearly be class objects.) In the end, my choice of explicit setters is based on habit and personal preference. Opinions? ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Intro to OOP using ActionScript: patterns derail!
Dave Mennenoh wrote: Lots of programmers never need design patterns as they don't help much unless your architecting large apps, and lots of Flash programmers aren't developing those kinds of apps. Keeping your code organized however should be taught from day one and certain oop concepts are perfect for that. There are plenty of patterns that can apply well to small-scale projects: take undo. How would you cleanly support undo without Command? Other patterns like State, Adapter, Observer (especially to overcome the sadistic limitations of Flash's single callbacks -- MovieClip -- or single listeners -- MovieClipLoader)... all have uses even in a sporty little website tchotchke. Not every 'design pattern' is something like MVC or data mapping or dynamically-configured factories. On the other hand, I got your point. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] save swf
Jer Brand wrote: Uncompressed, yeah, that'd be ugly. But how does something like the following (guesswork code) perform? foo:BitmapData = new BitmapData() ; /* put your image data in there, with whatever method */ bar:ByteArray = foo.getPixels(myImageRect) ; var.compress() ; Again, mostly asking because I don't know enough about AS3/FP9. It's supposed to be using zlib compression on the ByteArray but for all I know it's still doesn't compress enough or quickly enough to be useful. I'm totally leaving out the question of conversion after post or Socket or whatever used server side to get the job done, but I have to assume it wouldn't be difficult using GD or ImageMagic. Well, it might be easier in Actionscript 3.0. I know that in 2.0 it was a major pain, even with gzip compression... I know Grant Skinner got it working, you might want to check out this blog entry: http://www.gskinner.com/blog/archives/2006/03/saving_bitmapda.html ... and this attempted util: http://www.quasimondo.com/archives/000572.php I've researched this problem before, and came to the conclusion that it was a last resort at best. But try out Klingermann's demo on Quasimondo and see how fast it runs for you. On some computers or connections it is very slow indeed. You may be able to optimize it, though -- if you try and succeed, please give back by posting it somewhere or open-sourcing it on a well-known site like osflash.org. If you aren't discouraged after all I've said, I wish you luck! ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Intro to OOP using ActionScript
I don't think you need to call it procedural. Just call it the basic building blocks that they will need for OOP (or procedural, for that matter). There's not that much difference, really, between OOP and procedural. OOP just encapsulates chunks of procedural code and its data. This is the correct answer. OOP probably isn't a bad framework in which to teach these things, but when you start teaching you may be surprised by how many students have a hard time grasping concepts that may seem simple to you, even as simple as the relationship between a class and an instance. You will also see students who blur through the work and get bored five minutes after each class starts... but they aren't the ones we're worried about. So rather than engage in an argument as to whether OOP or procedural is "better", we're basically asking: Do the additional distractions of OOP justify the payoff from learning it up front? If you're teaching fellow geeks, then yes. If you're teaching people with a more casual interest in programming, or (shudder) people who are required to take the class, you may want to keep it script-simple. Compare: var foo:Number = 1; var bar:Number = 2; trace(foo + bar); vs. class Cat { private var age:Number; public function setAge(age:Number):Void {this.age = age;} public function getAge():Number {return age;} } var whiskers:Cat = new Cat(); whiskers.setAge(1); var patches:Cat = new Cat(); patches.setAge(2); trace(whiskers.getAge() + patches.getAge()); Is it so unrealistic to suggest that the second example, while having a pleasant real-world basis, involves many more steps and logical leaps for an absolute beginner to understand? Maybe this is a strawman... I guess you could start with how getters and setters work in the first place, and use that to explain functions/methods. It just seems like a bit too much drapery to start out with. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Intro to OOP using ActionScript
Start small and work your way up. You don't need classes until the functions start to get unmanageable. That won't happen until you've thoroughly covered variables and control structures. By the time classes are necessary, the students should be relieved to have a way to organize their forest of elaborate functions. Even if they're introduced in an organic and natural way, like building a Swing application, they're going to just be one more distraction for people who are struggling with the syntax of a for loop. They're an intermediate topic, treat them as one. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] save swf
Jer Brand wrote: Coming from someone who's never done this, and doesn't know if it's possible, but: Would it be possible to capture your user created design in BitmapData (I was fairly sure there's a method to extract pixel info from a MovieClip, correct?) then transmit that back to the server and use PHP and the image libs to create a bitmap image? Again, complete shot in the dark here.. I'm not even sure if the BD produced by Flash is usable by any graphics library, PHP or otherwise. Yes, technically, but transmitting that much bitmap data from Flash to the server, pixel by pixel, takes a great deal of time and bandwidth. I strongly recommend against the attempt. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] save swf
bassam mohaisen wrote: Hi all I'm trying to do e-tshirt design where the user can desgin his shirt and add text or images so I need to know how can I save the design as image or swf for the design how can I take screenshot , if somebody know the concept and the code . all the text and photos will be load inside movie clip so if i need know how can i save the movie clip at runtime This is actually an extremely difficult problem. Flash is not able to create files in the way that you're thinking. Your best bet is to record the T-shirt design in descriptive terms: "this text field uses 24-point Impact, is at coordinates xy, is rotated 30 degrees; this image is blahblah.jpg, it's scaled to 120%, positioned at xy". Then send that information to a server-side script, written in PHP, Java, C#, or something, which uses an imaging library to create an image. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] [OT] Improve my design skills
Ron Wheeler wrote: One of the best books is Head First Design Patterns. Really nice code. Well explained and shows how to get a lot of mileage out of code through thoughtful design. It will make you a better coder and get you thinking about design in new ways. He was talking about graphic design, but I've skimmed Head First Design Patterns and I agree with you. If you know nothing about design patterns, the book eases you into it quite smoothly, with lots of examples and metaphors. Quality material for AS 2.0 and 3.0 coders who want to learn the true advantages of object-oriented programming. (I only skimmed it because I'd already learned patterns from the Fowler and Gang of Four books... if you're a real propellerhead, you don't need the more friendly approach of Head First.) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] [OT] Improve my design skills
Marcelo de Moraes Serpa wrote: Hello folks, I'm currently mainly a coder, but I also love graphics design and design in general. I would love to improve my overall design awareness. Does anyone have any book (or any other resource such as website, magazine, mailing list, whatever) to recommend ? If so, I would be grateful! About ten years ago, I read a book from Microsoft Press (really!). It was named "Desktop Publishing by Design." Half of it was tutorials for Adobe PageMaker (which are now utterly irrelevant), but the other half went into quite a lot of detail about the printing process, page layout, font selection, and particularly the EFFECT of different page layouts and font, graphic, and color selections on the tone and feel of your work. I don't know if the series is still around, but perhaps you can find an old revision of the book for pennies on the dollar. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS 2.0 constructor inheritance
Hans Wichman wrote: Hi, when the superclass has a default contructor without parameters, there is no need to call it explicitly. I'd like to turn it around though, no matter what or how you have defined them, always call them explicitly for clarity's sake and self documentation. So if the superclass constructor DOES have parameters, I can't call "new SubClass(parameters)" without explicitly calling the superclass constructor in the subclass constructor. i.e. this works: // in superclass definition public function SuperClass() { blah; } // in code var foo:SuperClass = new SubClass(); but not this: // in superclass definition public function SuperClass(parameter:Type) { blah; } // in code var foo:SuperClass = new SubClass(parameter); That sounds like a language quirk rather than the nature of inheritance, but I can live with it now that I've identified it. Thanks! ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] AS 2.0 constructor inheritance
Compare these two situations: class SuperClass { private var list:Array; public function SuperClass() { list = new Array(); } } class SubClass extends SuperClass { // when instantiated, the list variable is automatically initialized } This is as it should be. The superclass constructor is executed when the subclass is instantiated, as long as the subclass doesn't override it. class Button { private var clip:MovieClip; public function Button(clip:MovieClip) { clip.onRelease = Delegate.create(this, handlerMethod); } } class SpecialButton extends Button { // does not override the superclass constructor } In this case, code such as "var foo:Button = new SpecialButton(clip);" does NOT execute the superclass constructor. Instead, I need this: class SpecialButton extends Button { public function SpecialButton(clip:MovieClip) { super(clip); // now it works } } My understanding of inheritance is that I should not need to explicitly call the superclass constructor as long as I'm not overriding or extending that method of the superclass. What gives? Is it a language quirk? ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Q: Including class at compile w/o explicitly instantiating it
Steven Sacks wrote: If you do not do anything with an imported class, Flash will not compile it. Or, to take it a step further, make a class named ClassRegistry (or some such), which defines but does not instantiate private static instances of every class you want to load dynamically. Then just define one instance of that registry in each class that will do dynamic instantiation. class ColorRegistry { // all extend Color private static var purple:Purple; private static var blue:Blue; private static var green:Green; } class ColorLoader { private var registry:ColorRegistry; public function loadColor(className:String):Color { ClassLoader.getInstance(className); } } Every class which has an instance defined in ColorRegistry will be available for instantiation. It's a bit of a hassle when you're accustomed to stuff like Java's Class.forName(className) method, but it could be worse. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Preloading problem
Omar Fouad wrote: is there a way attach a library item from a loaded swf. I think this would be the best solution... This suggestion hits close to the correct answer. Really, if your library is so big that it's killing your app's startup time, your wisest option is to load the items on demand using MovieClip.loadMovie, MovieClipLoader, or some more elaborate strategy built on top of them. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Lines in textArea
Volker Scarpatetti - Advertis Interactiva wrote: Hi ! Is there a way to know how many lines are written in a textArea component when filling it up dynamically ? This is not a perfect solution, but if you know the TextField.textHeight when there is a single line, you should be able to do a bit of division (possibly compensating for leading and such) to figure out the number of current lines. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] [FP8, AS2] Rules of thumb: Coding tips?
Micky Hulse wrote: Pedro Taranto wrote: if you want to return diferent types in one function you dont specify any return data type Ah, sounds good to me. I was not sure if it was bad practice to not specify a type. Well, if you want to write strictly, and if you're interested in exactly what data type your method returns, you can specify a return type of Object (the parent of every other AS class): function getData():Object { // do calculations, return the result } var returnValue:Object = getData(); if (returnValue instanceof DataType) { do stuff; } else if (returnValue instanceof OtherDataType { do other stuff; } ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Flash Debugger's not up to it.
John McCormack wrote: Consider a Point variable pt:Point(100,200). This generates calls to x() and y() as expected. But the debugger intialisation of pt causes an uneccessary call to pt.length() and this inappropriately reset the variable Changed. Why are getters and setters called uneccessarily by the debugger? A getter defines the get method of a property. Properties have to appear transparently as public fields. The Flash debugger has to show the values of public fields. Thus it has to call the property getter to display the value. (And it has to store the current value of each field in the scope tree even if the end-user never expands it, right?) As an example, let's pretend we have a getter which adds the values of variables A and B. How is the debugger going to populate a tree view of the parent object if it does NOT call that getter? In my view, it's a self-evidently poor programming practice to write a property getter which makes changes to the property. Falls into the same category as combining short-circuiting with side effects in a conditional statement: yes, it works, and it can even be useful, but it's dangerously opaque. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Searching within XML
Omar Fouad wrote: com.xfactorstudio.xml.xpath??? where can i get it??? Well, XPath is just one way of searching through an XML document to get specific nodes. As you might guess from the package name, this particular implementation can be found at www.xfactorstudio.com . You can learn more about XPath itself at W3Schools, or from reading the official specification. Google will give you more links than I can, and faster. If you're working with XML even a little, XPath is worth learning. It's like regular expressions -- a specialized little tool that can make very tedious things extremely easy. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] RESOLVED: Flash 8 exception handling
Alan MacDougall wrote: This looks completely straightforward and identical to Java... but when I do it, it catches the generic error. Now, obviously an Error instance is getting caught, which means one is getting thrown, which means my InvalidPathFormatException IS being recognized as a subclass of Error! It's just not getting caught by the right block! And it's not a priority thing, because if I omit the catch block for e:Error, I don't catch anything at all (but I DO get debug output of the string "Error"). One of the comments for the relevant Live Doc solved my problem: you have to use the entire qualified class name in your catch statement. try { stuff(); } catch (e:com.mydomain.package.ExceptionClass) { trace(e.message); } This chapter from Colin Moock's book ( http://www.actionscript.org/resources/articles/603/1/Exceptions-and-Exception-Handling/Page1.html ) appears to miss this vital piece of information... I guess he tested it on a version of Flash Player that didn't have that bug? ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Searching within XML
Omar Fouad wrote: I am doing some application on flash that uses an XML file to store data... This application has a search form. I understand how to get through the xml by loops but i can't figure out how to get flash to know if this "word" is included within the xml nodes or not... Any simple idea? The steps would be something like this: 1. get all the nodes which might contain the word (probably as an array) 2. loop through the array, getting the string from each text node 3. use String.strpos to see if the word is present. Which step is giving you trouble? My code would look something like this: import com.xfactorstudio.xml.xpath.*; function findInXML(rootNode:XMLNode, target:String):Boolean { var nodeArray:Array = XPath.selectNodes(rootNode, "xpathQuery"); for (var i:Number = 0; i < nodeArray.length; i++) { if (nodeArray[i].nodeValue.strpos(target) != -1) { return true; } } } And there you go. The XPath query would be something like "parentNode/childNode/text()". ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] Flash 8 exception handling
Okay, here's one for you. I extended Error with a very simple specific error type, like this: class com.mycompany.exceptions.InvalidPathFormatException extends Error { public function InvalidPathFormatException(message:String) { if (message != null) { this.message = message; } else { this.message = "General message for this error type."; } } } Now I try to use it with a method like this: /** Does stuff. @throws InvalidPathFormatException */ public function doSomeStuff():Void { if (anErrorOccurs) { throw new InvalidPathFormatException("error message"); } } I call this method like this: try { doSomeStuff(); } catch (e:InvalidPathFormatException) { trace("caught the specific error"); } catch (e:Error) { trace("caught a generic error"); } This looks completely straightforward and identical to Java... but when I do it, it catches the generic error. Now, obviously an Error instance is getting caught, which means one is getting thrown, which means my InvalidPathFormatException IS being recognized as a subclass of Error! It's just not getting caught by the right block! And it's not a priority thing, because if I omit the catch block for e:Error, I don't catch anything at all (but I DO get debug output of the string "Error"). Now, I think I'm doing this right -- I've done it in Java, and Colin Moock's book confirms that it's the same in Flash. What am I missing here? (All my exception classes are properly defined and imported or I'd be getting compile errors instead.) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] CDATA Html Text not working
Chris W. Paterson wrote: this.firstChild.childNodes[i].firstChild.childNodes[j].childNodes;--- this is how I am trying to access the content of that node. First off, I'm guessing I should use .nodeValue? Will that give me the entire node with ""? Is it even possible to read the html value for html text? Yep, there's the problem. The content of an XML node is a node in itself -- it's just a text node. It looks like this: my text --> part of node A my text --> node B --> part of node A So to get the text inside that tag, let's say we have: var fooNode:XMLNode; var textNode:XMLNode = fooNode.firstChild; var myText:String = textNode.nodeValue; myTextField.htmlText = myText; // now it should look right As you can see, the child node of is an XMLNode which contains the text -- it's not the string itself. I've used CDATA in XML plenty of times, and your HTML text fields will interpret the HTML as long as you're getting the string value of the text node. As for all that confusing child.firstChild.childNodes[n].child business, may I suggest XFactorStudios' excellent XPath implementation? www.xfactorstudio.com -- and then you can specify your XML with simple syntax like this: // gets an Array of XMLNodes; specifically, all inside a , starting from rootNode var nodes:Array = XPath.selectNodes(rootNode, "foo/bar"); It's a less confusing than manually walking the XML tree, and allows some pretty complex searches once you really get into it. ( http://www.w3.org/TR/xpath is very dense, but section 2 may give you an example of XPath's power.) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] swf obfuscation - new challenge
Danny Kodicek wrote: The only method I can think of that might do what you're looking for is to have some of the actual code work on the server. So for example you'd do something that has a fundamental effect in the game, but you make its code run on your server instead of on the client and just return the result (not that different from making a multiplayer game with server-side scripting and a dumb client). That's a good idea. It would have to be something with a real effect on the game, though, not just some authorization token which could easily be replaced or commented out. And then we're getting away from the real point of this sort of effort -- clients often want to keep their methods or innovations secret. You can't hide, say, a GUI component by backending part of it. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] obfuscation swf, and client demands
There's a constant demand for SWF obfuscation -- any good application, especially things like standalone games, is a ripe target for theft and rebranding. *cough ebaumsworld cough* And business clients are often afraid of plagiarism by real or imagined rivals: if they didn't want to be the first and the fanciest, they wouldn't be hiring us, right? Personally, I figure that if someone copies directly, it's obvious, and does them no credit; if they borrow ideas or even code concepts, good: a fellow programmer or designer is learning from my work. But clients don't always think that way -- and we have to keep them happy -- so this avenue of experiment is valuable and important. We always have to tell the client that absolute protection is impossible... but we can also tell them that we've put plenty of obstacles down. Code-hiders and code-crackers, play on! ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] AS 2.0 Tweening libraries
So, coming off the enterFrame() tween discussion, a lot of people mentioned various tweening libraries. I still use Fuse, which has proven extremely capable for my purposes; are there any pressing flaws in Fuse, or benefits in the other packages, that might convince me to change? ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Using createEmptyMovieClip to create MovieClips within MovieClips
2007/7/16, John laPlante <[EMAIL PROTECTED]>: > I'm writing a component and have created a MovieClip with > createEmptyMovieClip. When I try to create sub-MovieClip inside the > first MC with createEmptyMovieClip, it is undefined. This must be a > basic Flash thing. I haven't used createEmptyMovieClip too much. > > I tried > private var ItemContainer:MovieClip; > private var CContainer:MovieClip; > > this.createEmptyMovieClip("ItemContainer", this.getNextHighestDepth()); > this.ItemContainer.createEmptyMovieClip("CContainer", > this.getNextHighestDepth()); Try this instead and see what it comes up with: var itemContainer:MovieClip = this.createEmptyMovieClip("itemContainer", this.getNextHighestDepth()); trace(itemContainer._name); // should be "itemContainer" var subItem:MovieClip = itemContainer.createEmptyMovieClip("subItem", itemContainer.getNextHighestDepth()); trace(subItem._name); // should be "subItem" trace(subItem._parent._name); // should be "itemContainer" It's a good idea to make variable names start with lowercase; the usual code convention is that class names are initial caps, variable names are lowercase with internal caps. var classInstance:ClassName = new ClassName(); ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
flashcoders@chattyfig.figleaf.com
Van Tuck wrote: List -> A client is inquiring about a web-based system that would allow the user to type in a question, have the algorithm compare the input character-by-character to a predefined list of answers until all but one answer had been removed and the correct answer returned. Basically think of a huge list of answers out on a stage, then as user types in their question the forming string is compared and the incorrect answers disappear from the stage until only one remains, (that is if there is a predefined answer to that question). This is off the top of my head, but why not use a destructive binary search? Store all the answers in an array in alphabetical order, then each time the user types a letter, do a binary search on the developing string and Array.splice to eliminate all items that do not start with that string. It would only take a slight variation on binary search to rapidly destroy all non-matching items in an alphabetically ordered list. (If you want it to be undoable, restoring options as the user erases his string, just use variables to rule out items instead of destroying them.) Pseudocode: while (alphabetical array still has available options) figure out the middle index of the array (if array.length == 50, this would be 25) compare the item at the middle index with the input string if the input string is earlier in alphabetical order, rule out all items AFTER the middle index OR if the input string is later in alphabetical order, rule out all items BEFORE the middle index eventually you will have ruled out all items which don't begin with that string end while Note that if you use straight comparators (<, >), a string like "a" will be < "apple". In this case, you want to keep "apple" if the user only typed "a". So you'll have to do a little bit of string processing once you get down to that level. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods
Julian Bleecker wrote: That's great Ian — thanks for the help! Each of those little idioms makes sense when described — I never would've figured these out just whacking at various permutations, particularly the very baroque incantation leveraging the invisible symbol names. You may find it more convenient to consider MovieClip items as primitives -- or at least not worth your time to extend -- and create classes which wrap them. If you just want MovieClips to do particular things, or exhibit polymorphic behavior, you can probably get away with this: class Foo { private var myClip:MovieClip; public function Foo() { // create the MovieClip, possibly by // creating a new instance from the library } public function doThing() { myClip.doSomething(); myClip.doSomethingElse(); var tween:Tween = new Tween(some properties, myClip); trace("And so on"); } } I find this approach easier to work with and, since you could have more than one MovieClip in your custom object, more flexible. (Sure, Flash also lets you nest MovieClips ad infinitum, but moving away from parent.child.child.child is another benefit of going Java style.) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] How much do you charge for a Flash application?
Karthik wrote: Mates, I have a prospective client who wants to have a Flash application (AMFPHP). This is the first time for me so I need to know how much I should charge him. Can we please keep the list on topic? This is a coding-related list. Topics such as this and "Outsourcing" etc. should be confined to the Flash Lounge or elsewhere. And of course, the only answer anyone can give is "it depends." Try to estimate how many hours it will take you to do the job -- then pad it, because no job is ever as easy as it looks. Then just multiply that by your hourly rate. "What is a good hourly rate," you may ask? That depends on the cost of living in your area, the prices charged by your competitors, your own skill, and your chutzpah. Nobody here can tell you anything better. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] opportunity - paypal flash cart
stone larsen wrote: Josh, Didn't mean to step on your skill set, my thoughts were someone had one of these carts systems in thier library of files, something that could be repurposed. I can take the time to put this together, it's really not that much work, paypal handles the shipping/tax etc.. all that's being passed is the price total/size/color.. That would be fine -- I'm sorry if I came off so dismissive. I interpreted your original post as saying you wanted a shopping cart written from scratch, which is a whole different bottle of fish. $1000 to purchase and integrate an existing cart, with some customization to fit your site and needs, is perfectly reasonable. Do check out http://www.flashkart.com/ , as it seems to be an example of what you're looking for. And of course, a quick Google of "Flash shopping cart" turns up a host of other options. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] opportunity - paypal flash cart
Rich Rodecker wrote: check out flashkart. On 2/8/06, stone larsen <[EMAIL PROTECTED]> wrote: I am looking to hire someone for a fully functional apparel based flash cart using paypal as the merchant. Key needs: XML powered, easily updateable. If interested please hit me back, I'm not looking to spend over $1000. Best, S- And for future reference, if you're asking someone to code a full-featured professional-grade web application from the ground up, an offer of $1000 will only get you a confused shrug. There are very highly-paid people who can spend months on this kind of project. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] How do you code your Flash applications?
In your experience, are patterns useful in small projects? You know, I've been learning patterns through "C#.NET Design Patterns" and so far, to me, patterns only useful in big projects (in small ones, it might make things overcomplicated). Correct me if I'm wrong, please. Some patterns are only useful in big projects. But remember, patterns exist to solve problems -- some problems only occur in big applications, but some occur all the time. Let's take a simple example that could occur in any size of project, especially a Flash one: you want a particular object to react to user input. But you want it to react differently depending on the program state. For instance, maybe the user clicks an Erase tool, then clicks a drawing area -- that's different from if he clicks a Brush tool. One solution would be to write "if (tool == erase) { doSomething } else if (tool == brush) { doSomething Else }"... but you can see how that would turn your program into a horrible mess if each tool has complicated behavior. Instead, look up the State pattern in your GOF book. See? A design pattern that can have many uses, both large and small. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] How do you code... depth assignment?
Bryan Thompson wrote: Here here! Another negative vote for getNextHighestDepth(). The _root.removeMovieClip() gotcha when using v2 components wasted several hours of my time when first learning AS2.0 ... why the he!! can't I remove those clips! I use a custom class to assign depth just to spite Flash. There doesn't seem to be a lot of love on this list for the v2 components, and having looked at their code, I can see why -- but still, they have been getting the job done for me so far, and I'd suggest looking into the mx.managers.DepthManager class. I'm fairly new to the v2 architecture, though... if someone has some practical advice (or gruesome horror stories), why not share it? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] avoiding a stack of lists
That sounds to me like you want to use events -- the items which light up should listen to the items that trigger them. When the triggering item gets moused over, the listening item(s) can decide whether to react. This might just take your redundancy and put it somewhere else, but it keeps you from writing and checking a ton of different lists. Yeah, that sounds good. I haven't used events and listeners much, so upfront it might take me longer than my first approach. But let me see if I have the theory right. Each item in the lists is assigned a listener object as it is created, which would be a list of the possible events that will trigger it. Each item also has an event object that fires when rolled over. Rolling over item A fires an event that all the other items hear, each other item checks its list of events that will trigger it, and if it finds the event that was fired, it does its thing. Does that sound about right? Close. Let's assume you're using mx.events.EventDispatcher. Your event broadcaster class starts like this: import mx.events.EventDispatcher; class myClass { // function declarations to be mixed in by EventDispatcher public var addEventListener:Function; public var removeEventListener:Function; public var dispatchEvent:Function; /* constructor */ public function MyClass() { EventDispatcher.initialize(this); } } The EventDispatcher.initialize() call simply "fills in" the blank function declarations, and your object -- no matter what its type was before -- now acts as an EventDispatcher. Now let's say you have greenSwitch and purpleSwitch, which are event dispatchers; and redLight, blueLight, and yellowLight, which don't need to be. Given basic color theory, you want red and blue to light up if you click the purple switch. class Switch { ... public function toggle():Void { var eventObject:Object = new Object; eventObject.type = "onSwitchChange"; eventObject.target = this; // sends a reference to itself! dispatchEvent(eventObject); } } class Light { ... // note that this function has the same name as the event public function onSwitchChange(eventObject:Object):Void { // animate something, probably by altering a movieclip } } And finally, the code that makes use of these objects: var purpleSwitch:Switch = new Switch(); var redLight:Light = new Light(); var blueLight:Light = new Light(); purpleSwitch.addEventListener(redLight); purpleSwitch.addEventListener(blueLight); purpleSwitch.toggle(); As you see here, purpleSwitch contains an array of all objects listening to it; then when you create and dispatch an event object, it simply calls the identically-named method on each listener object. It's nothing mystical -- just convenient. And the nice thing about it, for your purposes, is that none of the switches or lights really even needs to know what color they are... the logic is contained in their sender/listener relationship. If you need something more complex, just add properties to the eventObject, and have the listener object deal with that. Or just read from eventObject.target, which should be a reference to the broadcasting object. The classic example is to have a textField or something, which sends events when it's updated; a listener could get to the text with eventObject.target.text. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] avoiding a stack of lists
Kent Humphrey wrote: I've made a single item work with my initial solution, which was to have a list for each item that lists which items in the other lists should highlight. But by the time I've made 25 lists for my 25 (current) items, that seems like a lot of redundant and duplicated data somehow. That sounds to me like you want to use events -- the items which light up should listen to the items that trigger them. When the triggering item gets moused over, the listening item(s) can decide whether to react. This might just take your redundancy and put it somewhere else, but it keeps you from writing and checking a ton of different lists. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Q: All OOP or ??????
What I ask myself on new projects is "what parts of this can I reuse?" Can I put this behavior in a class or a component? It's more work up front to make your classes for your daily tasks (not much more work) but on project 2 or project 3 your work will pay off. What's more, OOP design patterns often have powerful solutions to complex problems. If you get comfortable with OOP -- not just "using objects," but the true nature of "object orientation" -- you'll have an easier time when a really big problem hits you on the head. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Documenting my code
Ian Thomas wrote: Hi Alan, That one's pretty simple - we didn't even try. I too get the huge barf of 'no definition' output for the MX classes. But I didn't need to document the MX classes, so didn't bother looking into how to do so - the output from as2api _without_ those classes is absolutely fine for what we want. Hm, well, it's fine for me, too -- the multiple pages of errors just offends my tender sensibilities. Thanks! ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Documenting my code
Ian Thomas wrote: We've jsut started using AS2API - http://www.badgers-in-foil.co.uk/projects/as2api/ - which works fine for us on Windows (but had issues on Linux, sadly, although I think that's because our Linux box needs a good cleanup). Perhaps you could share how you got it working? I just tried it with a command line like this: as2api --classpath path/to/swfRoot;path/to/commonLib com.alanmacdougall.project.* (I have all my classes arranged properly at swfRoot/com/etc/etc, with utility classes like XFactorStudio's XPath at a common library location.) First it barfed when it found variable definitions in the style "private var x:Number, y:Number;" -- so I fixed those. But then it started giving me huge streams of errors saying "Found no definition of type known locally as 'MovieClip'". Again, I think, no problem -- I add flash_home/en/First Run/Classes/FP8 and flash_home/en/First Run/Classes/MX to the classpath... but without success. Could you post your experiences with as2api, and the command line parameters you're using? I'd appreciate it. Alan ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] An Issue of Encapsulation
Chris Kennon wrote: Hi, If my understanding of encapsulation is misguided, please correct. In the following code snippet, should in the interest if encapsulation, the "Good Morning/Afternoon" strings be called from another function? That depends on exactly how you interpret "formatTime". The point of encapsulation is not that your code embodies an ideal, but that it separates unrelated functions in a way that is useful to you. In the case of a time formatting function, I would argue that you might wish to put a string representation of the current time into many contexts. Maybe a character in a game says "It is now 12:34PM. Good morning!" Or maybe a desktop clock displays only mm:ss. Maybe a logging application displays a timestamp before every log message. It isn't likely you'll want to say "The current time is:" or "Good morning!" in all of these cases. It would probably be more useful to have a function, formatTime, which returns only a string representing the time itself; and then construct strings like this: "It's " + formatTime(myDate) + "! Time to make the donuts!" Or if you want the best of both worlds, do this: function formatTime(date:Date):String { // return the time string } getTimeGreeting(date:Date):String { var timeString:String = formatTime(date); var greeting:String = "The time is now " + timeString + "."; if (date.getHours() < 12) { greeting += " Good morning!"; } else { greeting += " Good afternoon... or night."; } return greeting; } This way, you have two functions, each of which does only what it should, no more or less. Just remember that "should" is always based strictly on the needs of your application... with a little room for future expansion or revision. A lot of the main point of encapsulation -- and object orientation itself -- is that it makes it easier to alter or re-use code later. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] SetInterval Magic
Dhiraj Girdhar wrote: Hi Guys, I am using second option of setInterval, but I am not able to understand the scope issue here. If you pass a function, the function is not called as part of its original class. An example: class myClass { private var myNumber = 5; public function doSomething() { trace("myNumber is " + myNumber); } } With setInterval(doSomething, 1000), you'll trace "myNumber is undefined" once a second, because the function is not being called as a method of myClass, so it doesn't have access to the other members of the class. With setInterval(this, doSomething, 1000), it works. Or setInterval(someOtherClassObject, otherFunction, 1000). Imagine that if you don't specify the parent object of the method, the method is "uprooted" from the object, and forced to exist as an anonymous function. Is there any solution other than Delegates? As, I am working for Flash 6 also. Before Flash 7, I think people wrote their own Delegate classes. Perhaps someone can provide sample code. I know that when I worked with Flash 5 and 6, I didn't know about Delegates at all, so I cursed the scope rules daily. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] SEO, flash site, url and text in this movie tags
Martin Weiser wrote: Hello, does these tags really work for search bots? No way. Google is way too smart these days. White text on a white background, tag text, text in comments, text anywhere a user can't read it -- Google ignores it all. Maybe it would work on other search spiders, but if you're not convincing Google, what's the point? The only way to get a good rank in Google is to have a lot of clearly visible, highly relevant, informative text, ideally with links to and links from reputable and well-traveled sites. Anything else is just a scam, and even if it works one month, it'll fail the next time Google rearranges their algorithms. Didn't I hear once that there was some way of letting Google search inside Flash files, though? Maybe someone else knows a better way of getting your Flash-based site ranked. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Advice on how to build a "click and drag" selector
Alan MacDougall wrote: I'm about to begin on a project for work where a user has the ability to select areas on a map by clicking and dragging his mouse over and area. When the person is finished they will let go of the mouse button and a nice little square will appear on the map where they have selected. Just use onMouseDown and onMouseUp handlers for the movieclip that contains your map. Record the _xmouse and _ymouse at each event. Those are the diametric corners of your new selection. Oh, and if you want a box to appear and resize in sync with the user's movements, have the onMouseDown handler create an onMouseMove listener, and resize the box each time that event fires. Then onMouseUp doesn't need to draw the box; it can just remove the onMouseMove listener and leave the box at its last drawn position. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Advice on how to build a "click and drag" selector
I'm about to begin on a project for work where a user has the ability to select areas on a map by clicking and dragging his mouse over and area. When the person is finished they will let go of the mouse button and a nice little square will appear on the map where they have selected. Just use onMouseDown and onMouseUp handlers for the movieclip that contains your map. Record the _xmouse and _ymouse at each event. Those are the diametric corners of your new selection. Here's a bit of pseudocode, which is not actionscript and won't work, but gives you the idea: var startX, startY, endX, endY; map.onMouseDown { startX = _xmouse; startY = _ymouse; } map.onMouseUp { endX = _xmouse; endY = _ymouse; drawSquare(startX, startY, endX, endY); } function drawSquare(startX, startY, endX, endY) { var squareMC = new MovieClip("squareGraphic"); squareMC._x = startX; squareMC._y = startY; squareMC._width = endX - startX; squareMC._height = endY - startY; } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] MTASC with v2 components
I have two MTASC issues: First, MTASC cannot compile MM's source for v2 components, because that source itself does not comply to pure, strict AS 2.0. The workaround is to use the -mx flag, which causes MTASC to use the precompiled .aso objects for v2 components. That's all well and good, but I need to alter the functioning of a specific method in a specific class (I need the Tween class's constructor to quit firing a start() command); and I can't extend and override the method without MTASC trying to compile the base class and barfing. If anyone knows an MTASC-safe way of compiling v2 components, I'd like to try it out. http://osflash.org/mx_v2_components_patch seems interesting, for example. But... Second, I wish to compile to a different location when I use MTASC. The last time I tried MTASC, I found that the .aso files it produced caused Flash to hang when I gave up and went back to MMC. If I could save MTASC .aso files to a different location, leaving the old MMC ones untouched, that would be pretty handy. I could be wrong about this one, now that I think of it; what is the relationship between MTASC and the compiled .aso files MMC generates? In my understanding, MMC stores precompiled objects and re-uses those when generating an SWF, assuming the actionscrip hasn't changed; MTASC does the same, right? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] what happens to exceptions i throw in async functions.
i am not able to catch this error in either the anon function or the function delegate. has anybody have any idea of how to handle asynchranous exception handeling in flash? I don't think you can do what you're planning, there; it appears that XML.load() starts a new execution thread, which ignores the try/catch block in which it was invoked. Your best bet for error handling is to analyze the XML in your onLoad handler. If you detect an error condition, let the handler deal with it. This does mean that instead of generating an exception and catching it, you have to do some logic to check for errors, but it seems to be Flash's way. Since Flash is designed for the internet, functions which instigate a new HTTP request are always going to run asynchronously -- since there's just no telling when the heck they'll complete. It's a compromise. Personally, I'd love to have the option of a synchronous XML.load() method, since often I'm just reading from files in the same directory as the SWF. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pathfinding
franto wrote: http://www.franto.com/blog2/as3-pathfinder-in-big-mazes with as2 and as3 sources, in as3 it's 100 times faster :) Yeah, I'm resigned to having to rework my entire application once ActionScript 3 hits the general-purpose Flash Player level. Unfortunately, you can never just wait for the next big thing, because if you do, there'll just be another big thing on the horizon. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] > Object repository and instancing a object
Weyert de Boer wrote: Hello I made a simple class to registers a class name and which should be able to instantiate a instance of a registered class. For example: TilesRepository = new ObjectRepository(); TilesRepository.registerObject( "DefaultTile" ); // create instance tileInstance TilesRepository.getInstance( "DefaultTile" ); My solution for that is to say "okay, how much unique information is in each Tile subclass?" For me, the answer is "not all that much." The main time to subclass is when you have different behaviors -- to take full advantage of polymorphism or common interfaces. For graphic tiles, the main differences are going to be values, not functions. For example, I'm working on a strategy game where there can be tiles of various terrain types. Each tile has object properties: {sprite:image, type:"jungle", moveCost:2}. I realized that a tile factory is a lot easier if I make just a single Tile class, which has these properties; and an XML file which maps default Tile property values to a unique tile type ID. moveCost="4" /> ... etc ... You initialize a TileFactory; the TileFactory loads this XML; then if I call TileFactory.getTile("uniqueName"), it scans the XML for the matching entry and draws the tile properties from that. Build and assist values for the tile, and return it, and you're all set -- without having to worry about instantiating classes from a string. Coming from Java, I was used to having a lot more freedom to instantiate classes dynamically, with Class.forName, but Flash is more friendly to other approches. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Importing custom components via Actionscript
[EMAIL PROTECTED] wrote: I wanted to load these cells from the library on the fly, but I get an error. Here is the code I use: import colorblock; c = _root.createClassObject(colorblock, "blankClip" + i, (i + 1), {colorParam:hexArray[i]}); Are you able to instantiate a new object of the class in the same scope? Does it compile if you try var testObj:colorblock = new colorblock(); (Also, I'd highly recommend changing class names to use initial caps -- ColorBlock instead of colorblock. It's such a universal standard that there's a slight chance the compiler is choking on the lowercase.) ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pathfinding
Toon Van de Putte wrote: Does anyone have a good implementation of a pathfinding algorithm, preferably for a typical side scrolling adventure game type interface? If you're talking about a top-view grid-based game, like Legend of Zelda or something, I have some code that's directly applicable. Mail me at "signal at alanmacdougall dot com" and I'll send it. If not, look up an algorithm named A* (pronounced "A-star") and code your own implementation -- here are a few links: A discussion of how the algorithm works, and why it's better than others http://theory.stanford.edu/~amitp/GameProgramming/ A very basic explanation of the algorithm's actual workings http://www.policyalmanac.org/games/aStarTutorial.htm An algorithm to figure out the set of possible destinations for a unit http://www.gamedev.net/reference/articles/article724.asp (I have a working Actionscript implementation of this too, if you'd like.) Alan MacDougall ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Comment/documentation debate
Some of this debate may be a matter of preference or perception, too. It's very true that good code should be self-documenting, but once you have a class more or less done, you shouldn't have to analyze its code to figure out what its methods and their signatures are, or how it interacts with other classes. And as a coder, I prefer to write a few lines of documentation comments (/** */ JavaDoc style) before each class and method -- it helps me focus my thoughts on exactly what the item should do and how it should work. It sounds like JesterXL is just coming from a very intense and fast-paced workplace, with a lot of constant hacking and refactoring -- just remember that the agile methodology wasn't devised to take emphasis away from planning and reflection; it was devised to take emphasis away from Byzantine management and communication structures. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] controlling the framerate of a swf file at runtime
Anyone know if it's possible to control the framerate of a movie at runtime? As far as I know, framerate is built into the SWF; it's a base property. If this has changed in the last one or two versions, I haven't heard about it. In a frame-by-frame animation, there'd be workarounds -- for instance, you could take the animation process out of the frame system entirely, and use setInterval to loop through frames at the speed of your choice. But once you introduce sound data into the equation, I have a feeling your options dramatically decrease. I hope someone with more Flash multimedia experience can suggest another workaround. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Displacement Maps, and Button actions
Howard Nager wrote: Thanks - the buttons are rectangular - any tips on how to calculate the corner positions if the displacement map is a gradient distorting on both x and y? I don't know the math behind the displacement map (I glanced at the formula and decided not to figure it out unless I had to!) If you do a little trial and error until you can get a single point to match, you should be able to calculate exactly how each gray value translates each point. The documentation for the DisplacementMapFilter object does list the formula, which should be a good starting point. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Displacement Maps, and Button actions
Howard Nager wrote: Mini update - I've simplified and am loading an image in to a movieclip and applying the distortion filter to the movieclip. Much easier...anyhow, before applying the distortion i am creating a button in that movieclip. The problem now is that the button visually distorts but the hit area doesn't follow. Is there any way to offset the hitarea according to the visual distortion? Since the hit area isn't bitmap data, you can't use a displacement map for it. A possible workaround would be to calculate the new distorted hit area and manually build a button with those dimensions, using MovieClip.beginFill, MovieClip.lineTo, and so forth. Then set its alpha to zero and place it where it'll intercept clicks meant for the visually-distorted button (which you should just disable). Assuming the button is originally a rectangle, and you're applying a static hand-made displacement map, you should be able to calculate or estimate the transformed corner points of the button. Now, if your displacement map is dynamic, you have a much sticker situation... ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders