[Flashcoders] AS3 to Java
Anyone know of any tools to convert AS3 code into Java? There seems to be several stabs at the other way around (j2as3 for example). Cheers Tom ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] Inheritance and abstract classes
Inheritance and abstract classes The examples I've seen are set up this way: Super class (abstract class) contains all methods Subclass overrides methods in super class Class instances are typed as super class and instantiated as subclass. I'm wondering why the examples show instances typed as a super class and instantiated as a subclass. This makes it necessary for all methods to exist in the super(abstract) class and overridden in the subclass. Is this on purpose so the abstract class acts as an interface? Wouldn't it be more flexible to type and instantiate as the subclass so methods can be added to the subclass that don't exist in the super(abstract) class? I like the idea of abstract classes. I'm just trying to figure out the best way to use them. Thanks. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] Downloading a .swc library
I posted this to another list a couple hours ago, and didn't get any takers, so I'll try here. My client wants something a little different. His specs call for a Flex program that, in code, embeds fonts from an external folder. He then wants to download that and use the fonts in another .swf. I'm thinking a .swc library is the way to go. I'm a little new to using libraries that way, though. Can I create the font .swc in a library project, and download it as I would a .swf or other asset? I know that's not the way a library is usually used. I would usually put the fonts in a .fla, export them to AS, and download the swf, but the client would prefer it all be done in code, and not using Flash. I have the file with the embedded fonts--all 16 of them. They work--Ihave 16 text fields on screen, also created at run time, each displaying text in the appropriate font. Can I just convert the embedding part to a .swc, download it, register the fonts, and use them? Would I use urlLoader? Another possibility--is it possible to export the embedded fonts to ActionScript, with code? I've done that plenty of times with embedded assets, but not assets generated at runtime. Cordially, Kerry Thompson ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Apple changes their guidelines
I'm not quite sure what the best way to send the app around is. Also the app performs significantly better on iPhone than the swf does on Android (the swf even performs better on iPhone with Frash) so looking at the swf in the browser will not get you 60FPS. Here it is though: http://www.unfocus.com/unBrix.refac.html The alpha transitions really hurt the software version (non-iPhone/AIR). If anyone has any suggestions about how to share the ipa... I'd be happy to send a fake-signed copy around. Notes: This performs at 59.1FPS on iPhone, ~52FPS in Frash/iOS 3GS - ~32 on Droid 2, and only ~45FPS in Firefox on Mac OS X (60FPS solid in Safari and Chrome)!! I haven't tested Android AIR yet (I suspect it'll be similar to iPhone because of cacheAsBitmapMatrix). Kevin N. On 9/22/10 1:17 PM, Tom Gooding wrote: Yes, I'd love to see this too, thanks for keeping us updated Kevin, nice one Tom On 22 Sep 2010, at 18:07, jared stanley wrote: wow 60 fps sounds impressive! i have not been impressed with the flashiphone demos adobe has been showcasing; they showcased the same blox game when they first announced it and again 6 months later just before release...i would love to see your example as it would be the first smooth-running demo i've seen. On Wed, Sep 22, 2010 at 9:29 AM, Kevin Newmancapta...@unfocus.com wrote: This all worked great. I now have the unBrix demo running at 60FPS - smooth as silk (almost, there are a very few small hiccups, nothing like in the previous demo - I have one last optimization left that I think will clean that up). The things I did were to make sure GPU acceleration is working (the bricks were red previously) - and preallocating (instantiating and storing) any and all objects I might need, and removing reliance on build in black box methods like hitTextObject. Actually, I separated the entire game engine into simpler shape objects (x, y, width, height - all int - final classes, no getter/setter, no inheritance) and did all the hit testing movement calculation manually on those, then apply that to scene in the render phase of ENTER_FRAME. I'll try moving it to RENDER event and see if that yields any improvement too (which'll be hard to spot!). Doing all that preallocation jives with what is mentioned in the packager for iphone dev guide PDF: http://download.macromedia.com/pub/labs/packagerforiphone/packagerforiphone_devguide.pdf In particular: Allocating fresh blocks of memory is costly. It can slow down your application or cause performance to lag during animation or interaction as the garbage collection gets triggered. and: As memory fills up, iPhone OS notifies other running, native iPhone applications to free up memory. As these applications process this notification and work to free memory, they may compete with your application for CPU cycles. This can momentarily degrade the performance of your application. For me, memory allocation has been the biggest cause for stuttering and visual lag in Flash on iPhone. I haven't posted the results yet, because I only finished this work at 3am. ;-) Also, certain properties like cacheAsBitmapMatrix aren't available in the Player swf builds (to run on Android or Frash) so I'm not certain a posted swf would truly represent these improvements (I'll try it anyway though). Hopefully I can finish and polish something within a few weeks or months and get it into the app store! :-D Kevin N. On 9/21/10 5:07 PM, Kevin Newman wrote: I've been attempting to tackle the same issues, and would love a lot more info, if there is any available, on how to get the framerates to be stable. I've actually had a bit of luck, and I'm currently operating on the theory that the problem lies with memory allocation/deallocation and the garbage collector. This seems to apply to any situation where the player might create objects that will have to be collected - including events (the event object - passed on dispatch), and maybe even functions in general (args array?) - and certain built in methods like hitTestObject, or txtFld.htmlText. Constructors are a killer. I'm in the process of refactoring this: http://www.unfocus.com/unBrix.html to aggressively remove all reliance on black box APIs (like hitTestObject) and create 0 (zero) new objects per frame, except the two event objects (ENTER_FRAME and possibly RENDER) and touch/mouse events. I should be done with that tonight, and then I'll have a better idea of what kind of impact that has if any on the performance, and most importantly on the lag spikes (for lack of a better term). In general, I'll also note that Frash (the hacked Android player on iOS) works far better in terms of scripting than the iPhone compiler - I hope the recent changes in Apple's ToS means that Adobe can just ship AVM2 and skip all this AOT compilation, since AVM2 from what I can tell, performs better anyway (it should help make the compile times bearable too). From what I'm seeing, the scripting has
Re: [Flashcoders] Downloading a .swc library
SWC files are zip files with swf files inside them (and some other misc stuff). The flash player does not know how to deal with them. You would have to unpack the zip, read the metadata and feed the stored swf to Loader.loadBytes. Or you could just load a swf like everyone else... ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Inheritance and abstract classes
Hi, If you type as a superclass you are generally programming to an interface, so you can just as easily type to an interface. Using interfaces is generally more flexible - it's easier to work with has a (interfaces) than is a (subclass), but sometimes you need a default implementation for your interface, which is why there are a number of abstract classes in AS3 that implement the interface - you need some generic behaviour, it can go in a super-class, but concrete classes are often difficult to deal with when you want to swap between interfaces. E.g. unlike C++ with multiple inheritance, you can only extend a single class, but you can implement as many interfaces as you want. People will generally tell you to work with interfaces, but there are times - and you will find out somewhere along the line, where only a superclass will do. For a simple example of this, look at what we do with Sprites and MovieClips when we extend them. Hope this helps. If you have not looked at Head First Design Patterns, or a similar book about patterns, then they will give you a more in-depth grounding than I can. Glen On 23/09/2010 17:42, Doug Lambert wrote: Inheritance and abstract classes The examples I've seen are set up this way: Super class (abstract class) contains all methods Subclass overrides methods in super class Class instances are typed as super class and instantiated as subclass. I'm wondering why the examples show instances typed as a super class and instantiated as a subclass. This makes it necessary for all methods to exist in the super(abstract) class and overridden in the subclass. Is this on purpose so the abstract class acts as an interface? Wouldn't it be more flexible to type and instantiate as the subclass so methods can be added to the subclass that don't exist in the super(abstract) class? I like the idea of abstract classes. I'm just trying to figure out the best way to use them. Thanks. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Downloading a .swc library
Henrik Andersson wrote: SWC files are zip files with swf files inside them (and some other misc stuff). The flash player does not know how to deal with them. Or you could just load a swf like everyone else... Fair enough. Here's the issue with loading the .swf. It's all code and no assets. I'm embedding fonts from external files on the fly. For example: [Embed( source='../fonts/Garamond3/GaramThrBolItaOsF.ttf', fontName='Garam3BoldItalicEmbedded', embedAsCFF='false' )] private static var Garam3BoldItalicEmbedded: Class; If I had these embedded in a .fla, I could export them to AS and have it working pretty quickly. The client wants an all-code Flex app, though. How do I access the fonts when they're not exported to AS? Make the private static vars public? If so, how would I use the font? textFormat.font = className.fontName; ? Cordially, Kerry Thompson ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Inheritance and abstract classes
Glen Pike skriver: has a (interfaces) than is a (subclass), That's wrong. HAS-A is not used for interfaces, it is used for reference properties and other forms of containment. Both interfaces and classes use the IS-A relation. You don't say Picture HAS-A IDrawable, you say Picture IS-A IDrawable. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Downloading a .swc library
Hi. I would think about using the [Embed] directive in pure AS3 code to create font swf files. You can have one or more fonts in a swf which does not matter and you can load them in a runtime dynamically. Here is an example of a Font file - you can setup a project in FlashDevelop that will compile this as the main class in a SWF file. For multiple Fonts, just duplicate the [Embed] line and the static variable for it (with a different name. Using an FLA - it does not embed the font ranges in the same way. I found there were only a certain range of characters in the IDE created SWF even when I changed the range to be embedded - only by de-compiling the SWF and looking at the glyphs embedded with Sothink's tool! If you need unicode ranges, this page is really useful: http://www.zenoplex.jp/tools/unicoderange_generator.html Also lots of links I have used to piece together my methods: http://blog.arwidthornstrom.com/2009/04/embedded-fonts-that-work-with-flash-ide-and-flex-sdk/ http://troyworks.com/blog/2008/09/12/flash-runtime-font-sharing-embedding-with-only-partial-character-sets-how-to/ http://www.betriebsraum.de/blog/2007/06/22/runtime-font-loading-with-as3-flash-cs3-not-flex/ http://developer.yahoo.com/flash/articles/runtime-fonts-as3.html http://www.ultrashock.com/forums/actionscript/font-embedding-using-flash-as3-and-flex-3-a-109509.html http://www.aaronwest.net/blog/index.cfm/2009/3/16/Lee-Brimelow-on-Creating-Runtime-Loaded-Fonts-in-Flash-CS4 http://mx.coldstorageonline.com/index.php?bid=48 The font is shown below - this is added to my config file - my application automatically loads any .swf files at startup (it is local, not net as a 7MB font with Traditional Chinese will strain your connection). If I change languages, my XML file may specify a font to find - IMPORTANT - the fontName in the XML matches the fontName in the Embed statement! My Application Screens all use a public static variable called _defaultFont, which can be changed at runtime by the following function and all my components can access the defaultFont variable should they wish to use it (a snippet of XML is shown at the bottom). Hope this helps - you can follow the links and work it out yourself if you want, or peek below: Glen protected function _findLanguageFont():void { var langXML:XML = languages.language.(attribute(lang) == languageCode)[0]; debug(this, will check for languageCode + languageCode + in + languages.language.toXMLString()); _defaultFont = null; if (langXML) { if(0 != langXML.attribute(fontName).length()) { debug(this, Language has font + langx...@fontname); var fonts:Array = Font.enumerateFonts(false); for(var i:int = 0;i fonts.length;i++) { var fnt:Font = fonts[i]; if (fnt.fontName == langx...@fontname) { _defaultFont = fnt; debug(this, Language set _defaultFont to + defaultFont.fontName); break; } } } } } package { import flash.display.Sprite import flash.text.Font; /** * Times font embedding class example. * Whatever you set the fontName property to is what you use as the fontName property in the config file for the app. * * This is different to embedding fonts with Flash because you can: * * 1. Set the unicodeRange - specify certain characters / ranges to embed, reducing file size. * 2. Choose your own fontName to avoid font clashes at runtime. * 3. Register the font in the file - the contstructor is called as the swf is loaded because this class is the * document class, so all you need to do is look for your font by fontName in your app. * * NB - Adobe's UnicodeTable.xml file was used to get the ranges for unicode, which omit the ? and a few other chars, so * this was doctored to include those (basically U+0300-U+030A,U+0041-U+005A was combined into U+0030-U+005A. * * @author Glen */ public class _Times extends Sprite { //Basic Latin characters + some punctuation - don't use the Adobe UnicodeTable for Basic Latin - it misses ? = 0x030F [Embed(source = C:/WINDOWS/Fonts/TIMES.TTF, fontName = _Times, fontFamily = Times, mimeType = application/x-font-truetype, unicodeRange = 'U+0020-U+002F,U+0030-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')] public static var _font:Class; public function _Times():void { trace(Font Loaded:: _Times); Font.registerFont(_font); } } } Sample XML config file for the application - the asset called ?xml version=1.0 encoding=utf-8 ? data assets asset swfFile=icons.swf/ asset niceName=Font_Times
Re: [Flashcoders] Inheritance and abstract classes
On 9/23/2010 3:51 PM, Henrik Andersson wrote: you say Picture IS-A IDrawable. Despite what the naming conventions are, since the only thing, IMHO, that interfaces are useful for, is determining if the object being passed to a method complies and has methods/properties that can be used, without having to write code to check if the object being passed actually has all the desired methods/properties. e.g. According to my understanding: human, cat, dog are different objects, but they all have an IMoveAround interface So I know If I pass one of the objects to a method that it can use the blueprints defined by the interface without something breaking, and have each walk,crawl, Jump, etc... in their own way. so shouldn't it be has-a? or it-has? or they-have? or is-able? Maybe I am not experienced enough with solid OOP, but that's the way I am understanding things right now. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Inheritance and abstract classes
Despite what the naming conventions are, since the only thing, IMHO, that interfaces are useful for, is determining if the object being passed to a method complies and has methods/properties that can be used, without having to write code to check if the object being passed actually has all the desired methods/properties. You can already do that with a class. As long the language is static typed (or is dynamically typed but types contranis are enforced at compile-time, as in AS 2.0 and in some cases AS 3.0), the compiler checks that without the need of an interface. I'd say that, conceptually, an interface is every method and property (and event, arguably) that a type exposes. So, you know x, y, height, widht, etc, are part of DisplayObject's interface (even though DisplayObject is a class; one you cannot instantiate or derive from without crashing at runtime, though; but that's more a hack hardcoded in the player for the lack of support of abstract classes in the language; and if you ask me, DisplayObject should have been an interface or there should be an IDisplayObject interface, but I digress). Now, knowing an object has certain capabilities is very useful, especially when writting libraries, frameworks and that sort of code. Your code could declare that it accepts objects that comply with certain interface (and here I don't mean necessarily the interface keyword / construct, but rather what I said in the previous paragraph). This is what you pointed out. But the difference is that you can have an object implement an interface without coupling it with some concrete class. So it's more flexible and it's possible for some object to implement more than one interface (and possibly unrelated interfaces). In a game, for instance, you can have entities (or whatever you like to call it). Following you IMoveable example, you could have other interfaces such as IShooter, IHitable, etc. You can have an engine that checks collisions and accepts IHitable objects; another engine would be in charge of moving the objects around and so it takes IMoveable object; another could be in charge of common tasks that need to be performed on shooters, so I'd act on IShooter's; and so on. Now, the advantage of using interfaces is that you can combine these sets of functionalities (as declared by the interfaces) in one object indepently, without having to force inheritance relations that might not make sense and could add nasty side-effects. I.e. an object could be hitable but not moveable, a shooter could be either moveable / not moveable, etc. So you could have a turret (IHitable, IShooter, but not IMoveable), and wall / obstacle (IHitable but not IMovable nor IShooter), and enemy ship (IHitable, IShooter and IMoveable), a bullet (IMoveable and IHitable but not IShooter since it doesn't shoot by itself). Without interfaces and only realying on inheritance this could turn into a mess rather quickly. This is important in languages such as Actionscript (which took the idea from Java), because multiple inheritance is not allowed. In other languages such as C++, you can have a class inherit from (and hence being-a) any number of classes so the interface construct / syntax is not necessary (although multiple inheritance has other drawbacks and is more complex, and that's why it was left out of Java and other languages followed it this idea). That said, you don't need to have interfaces or even abstract classes for everything, in my opinion. This adds flexibility and some space for future expansion but it comes at the cost of making things more complex. If you're writing a library and want to allow different clients to use it, having your methods accept interfaces instead of concrete / abstract classes is a good idea. You can even provide some default / minimal implementation but leave it open to your clients to implement their own and still be able to use your library, without having to extend some class (which is not always possible / practical). In lots of application code, though, I think you don't really need this extra flexibility and many times it adds more work for little benefit. Cheers Juan Pablo Califano 2010/9/23 Anthony Pace anthony.p...@utoronto.ca On 9/23/2010 3:51 PM, Henrik Andersson wrote: you say Picture IS-A IDrawable. Despite what the naming conventions are, since the only thing, IMHO, that interfaces are useful for, is determining if the object being passed to a method complies and has methods/properties that can be used, without having to write code to check if the object being passed actually has all the desired methods/properties. e.g. According to my understanding: human, cat, dog are different objects, but they all have an IMoveAround interface So I know If I pass one of the objects to a method that it can use the blueprints defined by the interface without something breaking, and have each walk,crawl, Jump, etc... in their own way. so shouldn't it be has-a? or it-has? or