Flash: 4 XML and TextField tips
Tip1:
Which converting back and forth between XML and Objects (e.g parsing), you can't use E4X like primitives e.g.
if(xml.@someAttribute != null) //won't work
Use
if(xml.hasOwnProperty("@someAttribute"){
instead.
Tip2:
Similar when comparing XML nodes you should probably convert it to a string first e.g.
switch(xml.@name.toString()) {
case "config":....
Tip3:
When dealing with TextFields and you to embed text into the fla, but want to scroll a textfield, and avoid loading text. By default the textfield will maximize to fit the size of whatever text is pasted into it, making it hard to layout
A solution is to use two dynamic TextFields, one for the scrolled display, the other a text holder, just paste the text into that making it as big as needed, then hiding it and copying the first textfield. via
body_txt.htmlText = hideMe_txt.text;
hideMe_txt.visible = false;
Tip4:
embed fonts with textfields in a layer masked by another layer with a graphic not over the clip. That way you can be sure what your getting, when working on the Timeline you will see everything, but when published it won't be visible. You can also and get precise letters, rather than embedding the entire font family in the library.
Flash:Flickering Animation, dissapearing animation => corrupted symbol
This is something I've hit a few times across several projects. At some unknown event, animated movie clips will start flickering, like if you have a character the head will start to dissapear on or off. Once one clip is broken, EVERY animation across the Fla will have flickering issues. Like simple tweens will show the first few frames, cut out completely then show the last.
Not sure how this is caused, guessing it's more frequent if your merging Fla's. The only solution I've found is going through animation by animation and trying them out in a separate Fla. Finding the one that flickers, and deleting it and replacing it with a backup will correct...the entire file!
Flash: Centering and Scaling
Been working on some fluid layout and centering projects. For reference:
- stage.width + stage.height - the size of the content on the stage.
- stage.stageWidth + stage.stageHeight - that dimensions of the monitor the flash player is currently consuming
- loaderInfo.width + loaderInfo.height - that of the Fla's publish settings
Got the 2nd and 3rd confused, so only started seeing problems when they were published (doh!)
Flash: Actionscript 3.0 ReferenceError: Error #1056 Cannot create property
Also discovered here Quote:
In Flash CS3, when you have instances (Movieclips) on the main timeline (Stage) with instance name on them and “Automatically declare stage instances” is off (File->Publish Setting->Flash->Actionscript 3.0 setting), You will need to declare properties for the document class with the same instance names or else you will get the error messages…
Like:
Cannot create property ANamedClipOnTheTimeline_mc on com.yoursite.DocumentLevelClass
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at com.yoursite.DocumentLevelClass()
In my case this was due to copying a button that didn't belong, hidden behind another clip. To Find it I selected all, Right Clicked, selected distributed to layers, and then deleted the offending layer named that of the clip named in the error.
Flash: Full window flash, and when minimum size scrollbars with SwfObject 2.0’s Dynamic Publishing
In the post "Elastic flash with scrollbars" a nice javascript library is presented to scale full window flash when the browser hits a certain. point. Worked great with SWFObject 1.0, but didn't work with SWFObject 2.0 and dynamic publishing without a tweak.
Here's the Javascript I'm using:
-
-
var params = {};
-
params.allowscriptaccess = "always";
-
params.menu = false;
-
var attributes = {};
-
attributes.id = "flashUI"; // what to call with External Interface
-
attributes.name = "flashUI";
-
swfobject.embedSWF("index.swf", "contentToReplaceDiv", "100%", "100%", "9.0.0", "expressInstall.swf", fv, params, attributes);
-
-
var scale = new FlashScaler("flashUI", 1280,768);
-
scale.resize();
This got the scaling to work but not on the original load, if the window was smaller than the minimum dimensions, as the load event has already been called. So I had to modify FlashScaler to call the resize function during constructor e.g.
-
-
function FlashScaler(flashdiv,w,h){
-
-
var flashObj = document.getElementById(flashdiv);
-
var minW = w;
-
var minH = h;
-
addWindowEvent("onload",resize);
-
addWindowEvent("onresize",resize);
-
resize(); //<-- added this line
-
.........
SWFForceSize is similar. "Size limiting for full window flash" Not exactly sure how they differ internally, but the approach that might work is hinted in the documentation and API But only when static publishing via the use of
-
-
swfobject.getObjectById(objectIdStr)
and perhaps passing it into SWForceSize? Don't know.
UPDATE: FlashScaler with this approach doesn't work with IE6, or IE7, gives script errors, looking into it.
Flash: Tip to find Clips lost in the library
If you have deeply nested folders in the library and/or drag things in from other Fla's you might not be able to find where they are. One tip is to find it, or drag it to stage from the other Fla and right click 'swap symbol' it will pop open the library viewer where it's at.
Flash: “Error initializing Java Runtime Environment - You may need to reinstall Flash.”
I've been trying to create a swf with about 100MB of uncompressed jpegs in it. Not surprisingly Flash opening it up expands to a whopping 1.5GB of ram, and then complains it ran out of memory during publishing it (even though the machine has 3GB of ram..), just prior to that it gives that error.
http://blog.tukker.org/2008/05/23/flash-cs3-error-initalizing-java-runtime-environment/
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&catid=612&threadid=1184131&messageid=4278084
This didn't make sense initially. But then I realized that adobe is likely using Java in the background to do the compilations, perhaps even embedding the FCSH., which would allow them to write the very difficult compiler in a cross platform way.
This might also explain why Flash (and Flex/Eclipse) hang for periods of time, as this is typical of garbage collection, and the larger the memory the longer it takes to do the sweep.
Flash: Error #1009: Cannot access a property or method of a null object reference.
Here's another needle, in the heap and stack.
If you have an array and you trace it out like so:
var ary:Array = [1,2,3]
trace(ary);// outputs 1,2,3
Behind the scenes, each element in the collection has it's toString() function before returning the single string. This is fine and good. However, if there is an error in that in the toString(), Even with debugging enabled, errors won't show up with a line number, leaving you head-scratching. In my case the toString function was overridden from a parent class, and didn't initialize variables due to missing a super() in the subClass's constructor.
Rants on Flash Player and Acrobat Reader
I starting web programming originally in Java, during it's heyday. Java had the grand vision "Write once, run anywhere" which turned into "Write once, test everywhere" with all the variances between different VM's and between upgrades. Ironically Java is still around, I still use it, and despite the massive increases in processor and memory, it's has grown in features to the point, developing with tools like Eclipse seem to be the same speed they were a decade ago. Sadly, flash appears to be following in it's footprints.
While this has been an amazing 2 years for flash, it's also been one of the most tumultuous..and the change appears to be going faster. In some ways every minor version of the flash player is more substantial in changes than some of the earlier major releases in lines of code (Just guessing). I often wonder why they bother calling it Flash player 9, when so many features changes, gaps and issues exist between minor versions, nad the transparent install still somewhat annoying on FireFox at least. Damn marketing people.
While I truly love aspects of flash, there are times like this when I feel like becoming a monk. One of the reasons I got into flash was I was tired of the issues between different browsers, now I'm not sure how much better we are. There have been nasty surprises where at times even Adobe's own components have been broken, but only on a specific minor version, and only when doing things like tweening Given the challenge in testing richly interactive sites, the visual nuances that are involved, having to test 8 minor verisons x 2 platforms x3-4 browsers by hand, really sucks ass.
I know from talking to the Flash Player QA team, they are doing I assume the best that can be done, they have a huge battery of Unit tests that are run regularly. But we rich media developers are a greedy lot. The features they are doing are exponentially more complex and they are facing the law of exponential growth....as the number of features are added, the possible interactions between them grows exponentially, and the normalization of the problems takes longer to stabilize... and this too sucks ass for us developing, I expect more quirks in the next year or two instead of less. Finding and working around quirks is about as much fun as peeling bubble gum out of kids hair. Toss in AIR growing pains, Flex considerations, and an already huge ecosystem of vastly different things and strategies calling themselves 'flash'. I know I'm having a hard time keeping track of just what features are supported, it's probably next to impossible task to keep things stable.
While I don't plan to give up on Flash. I actively loathe what Acrobat/PDF has become in the last year. Little pockets of the web, the Adobe browser...IMO trying to compete with IE, Netscape in a slightly subversive way. While I'm not a fan of HTML, right now using Adobe PDF on even basic PDF's has been a far worse experience than Browsers has ever been for me. Tons of hoops of fire for security and user preferences I don't care about. Bleh.
I've gone and only recommend people using FoxIt Reader which is faster, something like 1/10th size and ironically renders every PDF I"ve come across without problems where lately Adobe's version gives me more issues or actually crashes trying to read them...this latter I find completely mind blowing. For creating PDF's I find the PDF print driver from the PDF995 to be great, fast and friendly.
Like Flash (and AIR, and Flex..) I expect PDF's as a platform instead of document and viewer to solidify, but not anytime soon as they are still busy adding feature after feature. It's already taken about 1 year to shift gears into AS3.0 and gain about. I still have about 50% of my framework that has to be brought over. HOpefully this won't end up like the golden gate bridge in that when I get through converting it to AS3.0, that Flash 10 has come out and everything has to be redone again..
FlashRant: TypeError: Error #1006: value is not a function. *@#%!% !!
There are times when I really love flash, like the time I'm able to get something amazing done in a single day, that would take weeks to do in C++ or Java. Then like tonight, what starts out simple and should take just a few minutes, turns into an 10 hour excursion trying to figure out where a problem is, deciphering cryptic messages with no obvious relationship to what's going on. It's numerous of these experiences with flash's quirks that have resulted in me seriously contemplating becoming a monk.
Take this seemingly innocuous function:
-
-
function addTest(c:Class):void {
-
-
trace("addingTest ");
-
tests.push(c);
-
}
-
-
This is for a unit testing library I've developed for asynchronous tests. It neatly introspects a class for methods named a certain way and makes them into test cases. That works fine.
In the esoteric camp, trace isn't the normal trace. I override trace by making it a class variable, so I can point it to a external log (PowerFlasher's SOS) which has far better coloring, filtering, and searching than any other trace console I've seen. I do that like this earlier on.
-
-
public var trace:Function = TraceAdapter.NormalTracer();
-
This approach works fine everywhere, and I've been using it for months. However something about the overlap between the two cause the above error. When that's buried at the bottom of layers of code that normally works fine, it takes a long time to dig to find this needle in the heap and stack.
This is typical in much of the projects I end up with, where the issue is actually not a problem with either part but rather the interaction, making it very difficult to divide and conquer. The solution in this case, is in just that function to prohibit trace at all in that class..oddly in another almost identical class it doesn't have this issue!
