tag:blogger.com,1999:blog-85459862986203503682024-02-20T01:42:37.946-08:00Before I forget...Flash, Flex + ActionScript discoveries!Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.comBlogger41125tag:blogger.com,1999:blog-8545986298620350368.post-89258851180572437852011-10-10T19:54:00.000-07:002011-10-10T21:40:37.549-07:00Blog has moved...<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #444444; font-size: large;">This blog has moved. It has migrated to:</span><span style="font-size: large;"> <a href="http://craiggrummitt.wordpress.com/">http://craiggrummitt.wordpress.com/</a></span></div>
Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-67987493709706508842011-02-09T21:02:00.000-08:002011-02-09T21:35:48.091-08:00video whiteA recent task I had to achieve was to play a video for several seconds and extract a frame as a JPG several seconds in. I did not know the dimensions of the video ahead of time, so hoped to extract that information out of the video metadata, and create the video object at this point. Sounds simple enough!<br /><br />However, this only seemed to work about 75% of the time. Occasionally I was seeing just white in certain videos, like they weren't attached correctly to the Video object(despite receiving the metadata correctly). My theory was that perhaps the metadata was received after the FLV began playing, and that perhaps there can be problems creating a Video object and attaching a NetStream to it, after it has begun playing.<br /><br />So I tried creating the Video object and then resizing after receiving the FLV metadata, but the resize seemed to have no effect when extracting the Bitmap Data. But finally found a solution - the Bitmap Data extracted correctly, if I placed the Video object inside a MovieClip and extracted the Bitmap Data of the MovieClip instead of the resized Video object.Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-41910417517983499772010-11-27T01:48:00.000-08:002010-11-27T01:54:13.764-08:00SharedObject not updating between tabs<span style="font-family: arial;font-size:100%;" >Just created an app which required persistent data, so used a local SharedObject. However discovered that if one person had the app open in two different places(eg. 2 tabs) the persistent data in one tab wasn't updating in the other tab. To remedy this I tried reloading the SharedObject(SharedObject.getLocal) every time I extracted a variable, and yet this SharedObject variable still wasn't updating.<br /><br />Discovered that, strangely, the only way to update the SharedObject, is to first set it to null. Set it to null and then reload it forces an update.</span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-87062656292947071512010-10-18T03:13:00.000-07:002010-10-18T03:14:37.076-07:00Frustrating Flex problems solved #7 - Removing DragDrop animation<span style="font-size:100%;"><span style="font-family: arial;">In Flex was building a simple drag and drop from a library list to another simple list. I also wanted to build the functionality of dragging the item out of the simple list to automatically remove the item from the list, and return the item to the library.</span><br /><br /><span style="font-family: arial;">I managed to handle this with one problem remaining. As the dragged item thought it wasn't going to be accepted, it automatically played an animation of it returning to the simple list before my code displayed it back in the library. The animation was completely misleading but I couldn't find a way to turn it off!</span><br /><br /><span style="font-family: arial;">My solution in the end was to create a custom ListItemDragProxy component. I included this in the list with:</span><br /><span style="font-size:78%;"><span style="font-family: arial;">dragIndicatorClass="display.CustomListItemDragProxy"</span></span><br /><br /><span style="font-family: arial;">and in the custom class, I merely set visible=0 onMouseUp. Simple solution that works perfectly.</span></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-90848824061591330182010-09-09T14:24:00.001-07:002010-09-09T14:27:39.114-07:00Frustrating Flex problems solved #6 - Keydown<span style="font-family:arial;">Spent some time screaming "Why can't my component receive keyboard events? "</span><br /><br /><span style="font-family:arial;">Crazy, I'm not sure why i never knew this, but for a component to receive keyboard events, it needs to implement IFocusMangerComponent. And then, however you're trying to receive keyboard events, by overriding keyDownHandler, or listening for a keydown event, it should now receive these events...</span><br /><br /><span style="font-family:arial;">easy when you know how!</span><br /><br /><span style=";font-family:arial;font-size:78%;" >implements="mx.managers.IFocusManagerComponent"</span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-79819358757189939412010-09-03T03:18:00.000-07:002010-09-22T07:20:53.674-07:00Frustrating Flex problems solved #5 - ButtonBarButton bugs<span style="font-family:arial;">So i had a series of custom Buttons all set up perfectly in a ButtonBar, when I realised that the design dictated that one of the buttons was a different size than was happening with the automatic sizing system...</span><br /><br /><span style="font-family:arial;">So after discovering that the ButtonBar does not allow facility for resizing the width of a button, I had the choice. If i was going to extract the buttons from the ButtonBar, it probably would make sense to have them as a different type - Button for example. But reskinning my buttons as a different type could be time-consuming so I thought I'd see how I go just using ButtonBarButtons that aren't in a ButtonBar!</span><br /><br /><span style="font-family:arial;">All turned out fine, except that my labels weren't appearing. A little delving into the code and I discovered the following code inside spark.components.supportClasses.ButtonBase:</span><br /><span style="font-size:78%;"><br /><span style="font-family:arial;">// Push down to the part only if the label was explicitly set<br /></span><span style="font-family:arial;"> if (_content !== undefined)</span><br /><span style="font-family:arial;"> labelDisplay.text = label;</span></span><br /><br /><span style="font-family:arial;">For my two cents, there's something strange going on there... So to set the label, I need to put the text inside the label property, and i need to ensure that content is not undefined. Set content to something arbitrary and the label appears! weird...</span><br /><br /><span style="font-size:78%;"><</span><span style=";font-family:arial;font-size:78%;" >s:ButtonBarButton label="Title" content="nada"/</span><span style="font-size:78%;">></span><br /><span style="font-size:78%;"><span style="font-family:arial;"><s:buttonbarbutton label="Title" content="nada"></s:buttonbarbutton></span></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com1tag:blogger.com,1999:blog-8545986298620350368.post-40952466703881396102010-04-08T12:58:00.000-07:002010-04-20T07:22:45.381-07:00XML read error in AIR<span style=";font-family:arial;font-size:100%;" >Back to blogging, working on a couple of projects:<br /><br />I was importing an XML file using the standard technique of using a URLLoader, and in the result handler, setting the XML file with:<br /><span style="font-size:78%;">var result:XML = new XML(event.target.data);<br /><br /></span>But I found I had to move this to the FileStream class in an AIR application because the user had to specify the XML file to load. So I used:<br /></span><span style=";font-family:arial;font-size:78%;" >var result:XML </span><span style=";font-family:arial;font-size:100%;" ><span style="font-size:78%;">= new XML(stream.readUTFBytes(stream.bytesAvailable));<br /><br /></span>Suddenly I was getting a 1088 error on this line:<br /><span style="font-size:78%;">TypeError: Error #1088: The markup in the document following the root element must be well-formed.<br /><br /></span>After checking and rechecking the XML, I found that for some reason, there was a byte at the beginning of the byteString, which was causing havoc with reading the XML. So the String being returned by the readUTFBytes method had to truncate the first character. Like so:<span style="font-size:78%;"><br />var fileData:String = stream.readUTFBytes(stream.bytesAvailable);<br /></span></span><span style=";font-family:arial;font-size:78%;" >var result:XML</span><span style=";font-family:arial;font-size:100%;" ><span style="font-size:78%;"> = new XML(fileData.substr(1));</span><br /><br /></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com2tag:blogger.com,1999:blog-8545986298620350368.post-31427401050087242332009-11-16T10:04:00.001-08:002009-11-16T10:28:58.437-08:00latin flash tour<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCkzvdOIatDQt1uvJ8Xy0nHxxE3TlQTkJ7eLjo6Wf9jV5X9PZdVAqCCPRDsFKjnKZ-t9JxzLSdAGNk2JXwX3SgXRkOzajfWof-6ggltC09JN4qW7kSkBaevgNtVMYk2LyJpkw1Je7WoFo/s1600/IMG_2579.JPG"><img id="BLOGGER_PHOTO_ID_5404769910175358834" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 300px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCkzvdOIatDQt1uvJ8Xy0nHxxE3TlQTkJ7eLjo6Wf9jV5X9PZdVAqCCPRDsFKjnKZ-t9JxzLSdAGNk2JXwX3SgXRkOzajfWof-6ggltC09JN4qW7kSkBaevgNtVMYk2LyJpkw1Je7WoFo/s400/IMG_2579.JPG" border="0" /></a><span style="font-family:arial;">Went to the Latin Flash tour last week in Bogotá, and met Lee Brimelow. He went over and demonstrated some of the latest updates to Flash CS5 and the FlashPlayer 10.2.<br /><br />Features that got my interest: </span><br /><div><ul><li><span style="font-family:arial;">code snippets panel(frequently used code - similar to the old flash simple mode in old versions of Flash that people have complained about disappearing for years!)</span></li><br /><li><span style="font-family:arial;">code hinting(although I´ll probably keep using FlashDevelop)</span></li><br /><li><span style="font-family:arial;">FLA format is now an open format XML based file (with extension XFL) with all media external.</span></li><br /><li><span style="font-family:arial;">Font embedding panel - embedded fonts can be managed more easily</span></li><br /><li><span style="font-family:arial;">TLF text - a new text layout format which allows columns more easily(with editable text too!)</span></li><br /><li><span style="font-family:arial;">Multitouch event handling(if your hardware can handle it of course!)</span></li><br /><li><span style="font-family:arial;">Access to microphone data(turn your voice into darth vader apps coming up!)</span></li><br /><li><span style="font-family:arial;">Uncaught error event - Finally you don´t have to ensure you are catching every error possible to avoid the user ever getting a Flash uncaugh error message.</span></li><br /><li><span style="font-family:arial;">AIR - open a filetype with the default app</span></li><br /><li><span style="font-family:arial;">AIR - Filemanager API can now catch volume state change events(i.e. if the user plugs in a hard drive)</span></li><br /><li><span style="font-family:arial;">BUT of course! The feature that everyone talking and every question from the audience was about, was that Flash now has a feature to publish apps for the IPhone! No IPhone still doesn´t have a Flash Player, Flash packages for a native IPhone runtime. And the answer to almost every question about ´can the iphone apps do this´and ´can the iphone apps do that´was yes, it can do everything that the Flash player can do!(with the caveat that you just have to consider that performance might be worse on the Iphone)</span></li></ul></div>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-1135626687159945782009-11-03T15:03:00.000-08:002009-11-03T15:20:10.826-08:00Where in the world is Craig?<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN8f1wGc2vtHPDB2ijDAp0FcGq4vVxt3tMbt-j3wZ49tXDuX8TP0axLHcf38mMAnjspzHNt6vx506slaOehD8WZkZnejWg4R4EVBS-8jivaaMmtb6_yazM6cNVyKI_Qy_OaEvg-taWhg0/s1600-h/4057084622_03fec50efd.jpg"><img id="BLOGGER_PHOTO_ID_5400020590135432066" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 163px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN8f1wGc2vtHPDB2ijDAp0FcGq4vVxt3tMbt-j3wZ49tXDuX8TP0axLHcf38mMAnjspzHNt6vx506slaOehD8WZkZnejWg4R4EVBS-8jivaaMmtb6_yazM6cNVyKI_Qy_OaEvg-taWhg0/s400/4057084622_03fec50efd.jpg" border="0" /></a><br /><div>There´s been not much movement in this blog for a while because I´ve been travelling South America for a few months and am currently in Bogotá, Colombia. If by chance anyone in Bogotá is reading this, give me a shout. Would be very interested in meeting local Flash developers.</div><br /><div></div><div>In other Flash news, I´m heading to the Adobe Latin Flash Tour next Friday with Lee Brimelow speaking, will post an update here afterwards.</div>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-36554293115522462792009-06-28T23:49:00.000-07:002009-06-28T23:53:06.405-07:00Embedded fonts disappearing when loaded into another SWF<span style="font-family:arial;">I once found that when an AS3 flash movie(let's call it parent) that contained a UIComponent, loaded another AS3 flash movie(let's call it child) that contained a UIComponent with embedded fonts, the component within the child lost its embedded fonts.</span><br /><br /><span style="font-family:arial;">I also discovered that if the parent contained the font, then the component in the child was then able to find the embedded font, and all was well.</span><br /><br /><span style="font-family:arial;">However, this isn't an ideal situation, because I could imagine that you sometimes want the child movie to be able to operate independent of the parent, manage its own font embedding, or maybe not waste loading time of fonts in the main parent movie that may not even be required if the child isn't navigated to.</span><br /><br /><span style="font-family:arial;">I was prompted to revisit this dilemma in a </span><a style="font-family: arial;" href="http://forums.adobe.com/thread/453351?tstart=0">forum post</a><span style="font-family:arial;">, and it got me wondering what was going on. I can't find documentation to confirm, but I have a theory that once the parent has a UI Component it then tries to take over handling of the list of global Fonts that the child tries to access. This list of global Fonts maintained by the parent, doesn't by default have access to Fonts embedded in SWFs it loads.</span><br /><br /><span style="font-family:arial;">However to give the parent access to the font, the child needs to register its font with the global list with:</span><br /><br /><span style="font-size:78%;"><span style="font-family:arial;">Font.registerFont(ComicSans); //ComicSans for example</span></span><br /><br /><span style="font-family:arial;">This ensures that when the parent takes over handling of the global list of fonts, it has access to the font the child has embedded.</span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-64333159476160951782009-05-20T19:44:00.000-07:002009-05-20T21:57:02.365-07:00Component styling utility function<span style="font-family: arial;font-size:100%;" >In addition to an earlier post <a href="http://craiggrummitt.blogspot.com/2008/02/styling-text-in-instances-of-components.html">here</a>:<br /><br />I have put the sample code into a simple utility function that will apply a TextFormat style to any component or TextField, without needing to consider the specific syntax of the component.<br /><br />You can download this <a href="http://craiggrummitt.x10hosting.com/store/StyleUtils.as">here</a>.</span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-12918063775634577662009-05-13T23:37:00.000-07:002009-05-13T23:39:05.998-07:00'as' isn't the equivalent of typing.<span style="font-size:100%;"><span style="font-family: arial;">I guess I hadn't thought too deeply about it, but I always thought that the 'as' Operator was the equivalent of typing a variable.</span><br /><br /><span style="font-family: arial;">pseudo code example:</span><br /><span style="font-size:78%;"><br /><span style="font-family: arial;">type(x) = as type</span></span><br /><br /><span style="font-family: arial;">or to give a real world example:</span><br /><br /><span style="font-size:78%;"><span style="font-family: arial;">var myVar:String='3';</span><br /><span style="font-family: arial;">var myInt:int=int(myVar);</span><br /><span style="font-family: arial;">//or alternatively:</span><br /><span style="font-family: arial;">var myInt2:int=myVar as int;</span><br /><span style="font-family: arial;">trace(myInt,myInt2);</span></span><br /><br /><span style="font-family: arial;">But this code will trace:</span><br /><span style="font-size:78%;"><span style="font-family: arial;">3 0</span></span><br /><br /><span style="font-family: arial;">I've realised that while typing a variable actually converts the variable to the requested datatype, 'as' merely informs the compiler to expect a certain variable to be of a certain datatype.</span><br /><br /><span style="font-family: arial;">In the above example, 'myString as int' doesn't work because myString isn't an int.</span><br /><br /><span style="font-family: arial;">However, if initially we had defined myVar like so:</span><br /><span style="font-size:78%;"><span style="font-family: arial;">var myVar:*=3;</span></span><br /><br /><span style="font-family: arial;">The code would have no problem as myVar is an int.</span></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-85380376992594557142009-03-03T18:12:00.000-08:002011-10-10T21:33:20.757-07:00ComboBox direction<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: arial;">This blog has <a href="http://craiggrummitt.wordpress.com/2009/03/04/combobox-direction/">moved.</a> </span><br />
<br />
<span style="font-family: arial; font-size: xx-small;">I needed to force the Flex ComboBox to open in a specific direction. (I'm using a <a href="http://drumbeatinsight.com/">HTML Component FCKEditor</a>, which has to be on top, so I need to aim the ComboBox away from it, so it doesn't animate underneath it)</span><br />
<span style="font-size: xx-small;"><br /></span><br />
<span style="font-family: arial; font-size: xx-small;">It seems as though the only way to do this in Flex is to edit the mx.controls.ComboBox class itself. With some help from </span><span style="font-size: xx-small;"><a href="http://www.typeoneerror.com/forcing-combobox-component-open-direction-in-flex/" style="font-family: arial;">typeoneerror</a></span><span style="font-family: arial; font-size: xx-small;">, I went ahead and did just that:</span><br />
<span style="font-size: xx-small;"><br /></span><br />
<span style="font-family: arial; font-size: xx-small;">i added two booleans to the class to use to force the comboBox's direction:</span><br />
<span style="font-size: xx-small;"><br /></span><br />
<span style="font-size: xx-small;"><span style="font-family: arial;">public var forceDirectionDown:Boolean = false;</span><br /><span style="font-family: arial;">public var forceDirectionUp:Boolean = false;</span></span><br />
<span style="font-size: xx-small;"><br /></span><br />
<span style="font-family: arial; font-size: xx-small;">now in the displayDropdown method, inside the 'opening the dropdown' section, i just changed the if statement:</span><br />
<span style="font-size: xx-small;"><br /></span><br />
<span style="font-size: xx-small;"><span style="font-family: arial;">if (forceDirectionUp || (!forceDirectionDown &&</span><br /><span style="font-family: arial;">point.y + _dropdown.height > screen.height &&</span><br /><span style="font-family: arial;">point.y > _dropdown.height))</span></span><br />
<span style="font-size: xx-small;"><br /></span><br />
<span style="font-family: arial; font-size: xx-small;">There is still a problem, however - when I set the Combo to 'forceDirectionDown' and there isn't enough room at the bottom of the screen, when the dropdown closes, it assumes to animate the dropdown down, away from the combo. To resolve this, I added to the 'closing the dropdown' section, where it sets endY. I changed the condition line to:</span><br />
<span style="font-size: xx-small;"><br /></span><br />
<span style="font-size: xx-small;"><span style="font-family: arial;">endY = (forceDirectionUp || (!forceDirectionDown &&</span><br /><span style="font-family: arial;">(point.y + _dropdown.height > screen.height || tweenUp)) </span></span></div>
Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-25817318381206724212009-02-28T22:28:00.000-08:002009-03-01T14:13:28.260-08:00"Color" component parameter<span style="font-family:arial;">I never really understood why when you define a component parameter, you can define its type. Wouldn't the variable type that the parameter is related to, always define the type of the parameter? Aren't parameter and variable types synonymous? </span><br /><br /><span style="font-family:arial;">Well, it turns out that they are not necessarily.</span><br /><br /><span style="font-family:arial;">I've never paid much attention to the fact that you can specify the 'type' of a parameter in the Inspectable tag, as it was obvious to me that this would be the same as the variable type.</span><br /><br /><span style="font-family:arial;">But I've discovered at least one case where this is not so.</span><br /><br /><span style="font-family:arial;">Attempting to define an Inspectable variable as type 'fl.motion.Color' seems to work okay - it invokes the Color Picker in the Component Inspector when you click on the component on the stage. However when in the Component Inspector when you change the color from the default, and run the file, you'll get:</span><br /><br /><span style="font-weight: bold;font-family:arial;" >1067: Implicit coercion of a value of type int to an unrelated type fl.motion:Color." error.</span><br /><br /><span style="font-family:arial;">Obviously Flash expects the parameter of type 'color' to be related to a variable of type 'int'. Seems a little strange but there is a way to get around this apparent conflict between parameter and variable types of 'color':</span><br /><br /><span style="font-family:arial;">Specify the parameter to be of type 'Color' and the variable to be of type 'int'.</span><br /><br /><span style="font-size:78%;"><span style="font-family:arial;">package </span><br /><span style="font-family:arial;">{</span><br /><span style="font-family:arial;"> import flash.display.MovieClip;</span><br /><span style="font-family:arial;"> </span><span style="font-family:arial;">public class test extends MovieClip</span><br /><span style="font-family:arial;"> {</span><br /><span style="font-family:arial;"> </span><span style="font-family:arial;">private var _color:int;</span><br /><span style="font-family:arial;"> [Inspectable (type = "Color")]</span><br /><span style="font-family:arial;"> public function get color():int { </span><br /><span style="font-family:arial;"> return _color; </span><br /><span style="font-family:arial;"> }</span><br /><span style="font-family:arial;"> </span><span style="font-family:arial;">public function set color(value:int):void </span><br /><span style="font-family:arial;"> {</span><br /><span style="font-family:arial;"> _color = value;</span><br /><span style="font-family:arial;"> }</span><br /><span style="font-family:arial;"> </span><span style="font-family:arial;">}</span><br /><span style="font-family:arial;">}</span></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-85771136899323941932009-02-10T19:20:00.000-08:002011-10-10T21:33:37.045-07:00Flex - skinning the DateField icon<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: arial;">This blog has <a href="http://craiggrummitt.wordpress.com/2009/02/11/flex-skinning-the-datefield-icon/">moved</a>. </span><br />
<br />
<span style="font-family: arial; font-size: xx-small;">When adjusting the Date icon skin in a DateField component, its not sufficient to just use the css that Flex auto-generates when importing the Skin Artwork. In addition to 'skin', you must also specify that upSkin, overSkin, downSkin, disabledSkin are all set to null. otherwise they will supersede 'skin'. you do this for example, like so:</span><br />
<span style="font-size: xx-small;"><br /></span><br />
<span style="font-size: xx-small;"><span style="font-family: arial;">DateField {</span><br /><span style="font-family: arial;"> skin: Embed(skinClass="DateField_skin");</span><br /><span style="font-family: arial;"> upSkin: ClassReference(null);</span><br /><span style="font-family: arial;"> overSkin: ClassReference(null);</span><br /><span style="font-family: arial;"> downSkin: ClassReference(null);</span><br /><span style="font-family: arial;"> disabledSkin: ClassReference(null);</span><br /><span style="font-family: arial;">}</span></span></div>
Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com2tag:blogger.com,1999:blog-8545986298620350368.post-73969010091858066462009-01-19T15:15:00.000-08:002009-01-19T15:38:05.417-08:00adding classes dynamically Part II<span style="font-family:arial;">A little addition to a </span><a style="font-family: arial;" href="http://craiggrummitt.blogspot.com/2007/11/adding-symbol-dynamically-from-library.html">previous post</a><span style="font-family:arial;"> on adding symbols dynamically from the library. I was having difficulty adding classes(that weren't in the library) dynamically - they weren't being recognised. </span><br /><br /><span style="font-family:arial;"> <span style="font-size:78%;">var classRef:Class = getDefinitionByName("Square") as Class;</span></span><span style="font-size:78%;"><br /><span style="font-family:arial;"> var shape:IShape= new classRef() as IShape;<br />//Flash displays: ReferenceError: Error #1065: Variable Square is not defined.</span></span><br /><br /><span style="font-family:arial;">With help from Aaron Beall(on </span><a style="font-family: arial;" href="http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=665&threadid=1393183">adobe forums</a><span style="font-family:arial;">) who was having the same problem, i've realised that obviously flash doesn't know to compile the class if it only exists in a string. So we need to ensure that flash compiles every possible class that we may refer to dynamically. We can do this simply by declaring a variable of that class type.</span><br /><br /><span style="font-family:arial;"><span style="font-size:78%;">var squareRef:Square;</span></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-32274205650409119862008-12-10T15:29:00.000-08:002008-12-10T15:30:20.910-08:00CS4 component icon library bug.<span style="font-family: arial;">I've been wondering why items in my library disappear occasionally - including the library buttons and column headers!</span><br /><br /><span style="font-family: arial;">I've narrowed the problem down to a CS4 bug.</span> <span style="font-family: arial;">Steps to reproduce bug:</span><br /><span style="font-family: arial;"> 1.Create a MovieClip</span><br /><span style="font-family: arial;"> 2. Select 'Component Definition'</span><br /><span style="font-family: arial;"> 3. Add a parameter so that the component icon will become visible.</span><br /><span style="font-family: arial;"> 4. Select 'Seek Bar Control Icon' or 'Buffering Control Icon' as custom component icon.</span><br /><span style="font-family: arial;"> 5. Select 'OK'</span><br /><span style="font-family: arial;"> 6. Watch the craziness ensue!</span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-17968822662434214712008-11-18T21:07:00.000-08:002008-12-09T22:42:54.828-08:00jerky raster animations<span style="font-family:arial;">It has always bothered me that animations of raster images are always jerky when they get to the point of animating less than a pixel per frame. Flash assumes that rasters should only live on the exact pixel. </span><br /><br /><span style="font-family:arial;">This can be resolved with bitmaps that are created with ActionScript with the Bitmap.pixelSnapping value but for pure animation is a little more complicated.</span><br /><br /><span style="font-family:arial;">I've just discovered that if you adjust the scale, rotation or skew of the image, Flash will turn pixelSnapping off. So giving a slight degree(more than 0.1%) of one of these factors is the simplest way to demand no pixelSnapping, without requiring one line of ActionScript.</span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-41238336480418568792008-10-14T22:29:00.000-07:002008-10-14T23:02:19.965-07:00Stage dimension limitation - 214x137<span style="font-family: arial;">I was trying to work out why the Flash Player Settings window was not appearing when i attached a webcam to a Video object, when i discovered that my stage was too small. Although i can't find documentation for this feature anywhere, I have found through experimentation that for the Settings Window to appear, the stage must be a minimum of 214x137.<br /></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-55211187901505072612008-09-15T18:37:00.001-07:002008-09-15T18:37:56.900-07:00stage.mouseLeave and wmode=transparent<span style="font-family: arial;">noted a strange incompatibility today - the stage.mouseLeave event doesn't get triggered when you hold a mouse button down, and drag off stage on a flash object which has wmode set to transparent. in fact doing so takes the focus off the flash object so that regular stage events no longer get triggered until it receives focus again(say by the user clicking on the object).</span><br /><br /><span style="font-family: arial;">sounds obscure, but if someone's dragging a slider and somehow drags off the object, releases the mouse button and then returns to the object, the slider continues to move around with the mouse even though the mouseButton isn't down.</span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com2tag:blogger.com,1999:blog-8545986298620350368.post-88953233754371384542008-08-13T18:46:00.000-07:002008-11-04T04:51:10.628-08:00dynamic text fields part II<span style="font-family:arial;">just got back from a six week holiday, so was wondering if i'd lost my mind while i was away...</span><br /><br /><span style="font-family:arial;">steps to recreate weird problem:</span><br /><br /><span style="font-family:arial;">1. set up two dynamic text boxes on the stage - one bold and one not bold - both with letter spacing of 1.(hint at solution) give them instance names - text1 and text2</span><br /><span style="font-family:arial;">2. set their text attributes in actionscript eg.</span><br /><span style="font-size:78%;"><span style="font-family:arial;">text1.text="hello";</span><br /><span style="font-family:arial;">text2.text="there";</span></span><br /><span style="font-family:arial;">3. run out - notice that neither text box is bold.</span><br /><br /><span style="font-family:arial;">for some bizarre reason, giving the text box a letter spacing value!=0 means that it loses its formatting when you set its text value.</span><br /><br /><span style="font-family:arial;">to resolve either set letter spacing to 0, or follow my earlier post in setting text with a letter spacing value.</span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-80573313606932353452008-06-30T22:16:00.000-07:002008-06-30T22:30:01.520-07:00Frusting Flex problems solved #4 - preventing a DataGrid column from resizing<span style=";font-family:arial;font-size:100%;" >What a laborious problem this was!<br /><br />I had set up a DataGrid that resized with the browser, and the user could also resize the column widths. However one column contained a button, and needed to not be resizable by the user or by browser resizing. But in practice, the button was resizing smaller and smaller every time the browser was resized. After many forum postings a solution was suggested(thanks VarioPegged) that is not the most elegant but works:<br /><br />To recap, three steps must be followed:<br /><br />1. add a dummy datagridcolumn to the far right of the datagrid that is not resizable and has a width of 0.<br />2. give the column you don't want to resize a minWidth value.<br />3. set up an updateComplete event handler on the datagrid, which resizes the button column and then calls validateNow() on the datagrid.<br /><br />you can follow the newsgroup post on this issue <a href="http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=585&threadid=1370825"><span style="text-decoration: underline;">here</span></a></span>.<span style=";font-family:arial;font-size:100%;" ><br /></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-82795468602388398692008-06-18T22:59:00.000-07:002011-10-10T21:13:56.330-07:00dynamic text field part I - letter spacing<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: arial; font-size: 100%;">This blog has <a href="http://craiggrummitt.wordpress.com/2008/06/19/dynamic-text-field-part-i-letter-spacing/">moved</a>. </span><br />
<span style="font-family: arial; font-size: 100%;">Just discovered that flash resets the author-time letter spacing of a dynamic textfield when the textfield's text is set in ActionScript.<br /><br />To maintain the authortime </span><span style="font-family: arial; font-size: 100%;">letter spacing </span><span style="font-family: arial; font-size: 100%;">settings of the textfield, you need to record the textfield's textformat, set the text, and then reset the textfield's textformat to what it was. For example, if your textfield's instance name is test:<br /><br /><span style="font-size: 78%;">var fmt:TextFormat = test.getTextFormat();<br />test.text="New text";<br />test.setTextFormat(fmt);</span><span style="font-size: 100%;"><br />something to check is that if the textfield does not contain any text, the author-time TextFormat </span></span><span style="font-family: arial; font-size: 100%;">letter spacing </span><span style="font-family: arial; font-size: 100%;"><span style="font-size: 100%;">property is not recorded. So if you don't want your textfield to contain any text, make sure the textfield contains at least one space to ensure it maintains its author-time TextFormat </span></span><span style="font-family: arial; font-size: 100%;">letter spacing </span><span style="font-family: arial; font-size: 100%;"><span style="font-size: 100%;">property.</span></span></div>
Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com9tag:blogger.com,1999:blog-8545986298620350368.post-20901849717166308512008-04-22T20:02:00.000-07:002008-04-22T20:05:03.201-07:00Frustrating Flex problems solved #3 - DataGrid scrolling error<span style="font-size:100%;">I'm currently working on a project that requires me to be using Flex 2 rather than Flex 3(I'm using an older version of Zinc, and avoiding upgrading if possible as we'll probably be moving to AIR after this project). But - issues in Flex 2 are no longer supported...<br /><br />The problem i encountered was when changing the DataGridColumns and dataProvider of a DataGrid, it gave a #1010 error 'A term is undefined and has no properties.' when scrolling vertically.<br /><br />After trawling the web for answers, I found a diamond <a href="http://www.wietseveenstra.nl/blog/2007/03/27/flex-listbase-scroll-vertically-error/">here</a> from Marc Sulinski, who suggested the hack of extending the DataGrid class and overriding updateDisplayList with the following:<br /><br /><span style="font-size:78%;">override protected function updateDisplayList(w:Number, h:Number):void {<br />var b:Boolean = false;<br /><br />if( rendererChanged ) b = true;<br /><br />super.updateDisplayList(w, h);<br />if( b ) {<br />while( rowInfo.length > listItems.length ) rowInfo.pop();<br />}<br />}</span></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0tag:blogger.com,1999:blog-8545986298620350368.post-75819748396657989212008-04-01T15:45:00.000-07:002008-09-29T23:58:09.476-07:00ObjectCollection<span style="font-family:arial;">i'd set up a repeater to display data returned from a ColdFusion call - which would either be a Y or N. I wanted to adjust how this appears to YES or NO, and thought a straightforward way of doing this would be set up an associative array:</span><br /><br /><span style="font-size:78%;">[Bindable]<br />public static var yesNoTranslator:Object={N: "No",Y: "Yes"};</span><br /><br /><span style="font-family:arial;">and my text component would look something like:</span><br /><br /><span style="font-size:78%;"><text="{Constants.yesNoTranslator[repeater.currentItem.rsvpStatus]}"></span><br /><br /><span style="font-family:arial;">Flex Builder produced warnings on this, however:<br />"Data binding will not be able to detect changes when using square bracket operator. For Array, please use ArrayCollection.getItemAt() instead."<br /><br />Though in this case, i could ignore the warning and the app would work as desired, i could see that sometimes you may want your associative array to change and the binding wouldn't detect changes. Anyway, warnings are annoying to have hanging around, and for some strange reason they seem to propogate themselves in Flex Builder...<br /><br />As the warning describes, if yesNoTranslator was an array, i could use ArrayCollection.getItemAt() instead. yesNoTranslator was an object and there is no equivalent with objects(for some reason), so i thought the simplest thing to do would be to create one, which i've called ObjectCollection:</span><br /><br /><span style="font-size:78%;">package<br />{<br />import mx.utils.ObjectProxy;<br /><br />public class ObjectCollection extends ObjectProxy<br />{<br />public function ObjectCollection(item:Object=null, uid:String=null, proxyDepth:int=-1)<br />{<br />super(item, uid, proxyDepth);<br />}<br />[Bindable(event="propertyChange")]<br />public function getItemAt(index:String):Object {<br />return(this[index]);<br />}<br />}<br />}</span><br /><br /><span style="font-family:arial;">and modify my above code to:</span><br /><br /><span style="font-size:78%;">[Bindable]<br />public var yesNoTranslator:ObjectCollection=new ObjectCollection({Y:"Yes",N:"No"});<br /><br />< text="{yesNoTranslator.getItemAt(repeater.currentItem.rsvpStatus)}"></span>Craig Grummitthttp://www.blogger.com/profile/14325143883559624630noreply@blogger.com0