- Posted by Brent on August 27, 2008 01:30
I posted a few how-to articles on Adobe's Flex Cookbook site recently and to say thanks they sent me this great Flex 3 book from O'Reilly!
I'm not sure if the book was to say thanks, or if my articles were so crappy that they felt sorry for me and thought I needed to learn more about Flex!
Just kidding, my articles rock - check 'em out!
Thanks for the great book Adobe!
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
- Posted by Brent on August 20, 2008 14:24
Looping over the data used by a Flex List component is easy enough, but what if you need to loop over the actual itemRenderers in the List? Recently I needed to do just that.
I needed a reference to each of the itemRenderers so that I could pass TextInput controls in my custom renderer into a 3rd party spell check library. Anytime you want to do something with the controls inside each of the custom itemRenderers in your list, looping over them will come in handy.
The key to doing it with Flex 3 is understanding the mx_internal namespace. A lot of variables in the Flex framework are mx_internal variables. Variables in the mx_internal namespace are ones that Adobe thinks have a high probability of changing in future versions of Flex, so they reside in a special namespace so developers know they may change. Since the Flex framework is open source, we can easily open the code and find which variables are mx_internal.
The List controls inherits from ListBase. ListBase has a mx_internal variable named rendererArray. rendererArray is just that, an array of renderer's used by your List. If you try to access rendererArray using the standard List component you wont be able to. To gain access to this array we will need to create a new component that inherits from List. Below is the full source for my ExposedRendererList :
1: package Controls
2: {
3: import mx.controls.List;
4: import mx.core.mx_internal; //this import statement should appear be last
5:
6: public class ExposedRendererList extends List
7: {
8: use namespace mx_internal; //tells Actionscript that mx_internal is a namespace
9:
10: public function ExposedRendererList()
11: {
12: super();
13: }
14:
15: //The array of renderer's being used in this list
16: public function get renderers():Array
17: {
18: //prefix the internal property name with its namespace
19: return mx_internal::rendererArray;
20: }
21:
22: }
23: }
There are 3 lines of code we need to take a look at. The first one is line 4. We need to import mx.core.internal namespace into our new class. On line 8 we tell Actionscript that mx_internal is a namespace we will be using in the class. And finally we create a new property on our class named renderers. The only thing it does is get the rendererArray from ListBase (which is the parent class for List). We have to prefix rendererArray with the mx_internal:: namespace in order to gain access to it. Now we've exposed the previously internal array for use anywhere in our Flex application.
Looping over the renderers or components in each of renderers becomes pretty trivial. The one thing to keep in mind is that rendererArray is an Array of Array so we'll need to write our ActionScript accordingly. Here is a sample method the does a for...each loop over the itemRenderers in a List:
1: private function LoopOverRenderers():void
2: {
3: for each(var renderer:Array in coolstuff.renderers)
4: {
5: //renderers is an array of arrays
6: //in a List component, our renders will be the first element of each array
7:
8: if(renderer[0] != null)
9: {
10: ProductRenderer(renderer[0]).img.rotation += 90;
11: }
12: }
13: }
I'm also including the obligatory live example with view source enabled so you can view the full source code and/or download the sample app.
In the sample application, I simply rotate the image in each of the renderers 90 degrees to show I have reference to each itemRenderer and its therefore its child components.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
- Posted by Brent on August 4, 2008 04:24
The following is a simple example showing how to create a TextArea component in your Flex application that expands as the user types text into it. Basically what you need to use is the TextArea's textHeight property, and set it's value to the height property of the TextArea in the controls change event. The assignment must happen in the TextArea's change event.
Binding it directly does not work:
<mx:TextArea id="myText" wordWrap="true" width="350"
height="{myText.textHeight}"verticalScrollPolicy="off"
borderStyle="none" />
Instead use the change event:
<mx:TextArea id="myText" wordWrap="true" width="350"
change="{myText.height = myText.textHeight + 10;}" "verticalScrollPolicy="off"
borderStyle="none" />
A live example with view source enabled is available here.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
- Posted by Brent on July 1, 2008 00:13
I'm a recent newcomer to Adobe Flex development so when I read yesterday that Google has improved it's ability to crawl SWF files of all kinds, it put a
on my face. Google can now index the textual content in flash files of all kinds. They can also crawl URLs embedded in Flash files as well! How do they do it? Google says:
"We've developed an algorithm that explores Flash files in the same way that a person would, by clicking buttons, entering input, and so on. Our algorithm remembers all of the text that it encounters along the way, and that content is then available to be indexed. We can't tell you all of the proprietary details, but we can tell you that the algorithm's effectiveness was improved by utilizing Adobe's new Searchable SWF library."
Even better is the fact that Flex/Flash devs don't need to do anything special with their SWF files. Just keep on developing as usual!
According to Google, there are 3 limitation to crawling the text in your SWF files:
1. Googlebot does not execute some types of JavaScript. So if your web page loads a Flash file via JavaScript, Google may not be aware of that Flash file, in which case it will not be indexed.
2. We currently do not attach content from external resources that are loaded by your Flash files. If your Flash file loads an HTML file, an XML file, another SWF file, etc., Google will separately index that resource, but it will not yet be considered to be part of the content in your Flash file.
3. While we are able to index Flash in almost all of the languages found on the web, currently there are difficulties with Flash content written in bidirectional languages. Until this is fixed, we will be unable to index Hebrew language or Arabic language content from Flash files
You can read more about this here here here and here .
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5