Adobe Dreamweaver Forums



Last 10 THreads :         Re: Accurate measurements for printing (Last Post : Don_Gough@adobeforums.com - Replies : 0 - Views : 1 )           »          Re: Paint, erase, burn and dodge won't work for me in CS4 (Last Post : John Joslin - Replies : 0 - Views : 1 )           »          Re: Accurate measurements for printing (Last Post : Don_Gough@adobeforums.com - Replies : 0 - Views : 1 )           »          button rollover to keyframe help (Last Post : mrpetesurfs - Replies : 1 - Views : 2 )           »          Call out side flex (Last Post : G009 - Replies : 13 - Views : 14 )           »          Scaling .swf files to fit specific dimensions (Last Post : wolfsj - Replies : 0 - Views : 1 )           »          Array of Queries (Last Post : ptrott - Replies : 0 - Views : 1 )           »          Can't get Macromedia Authorware Web Player to install onWindows Vista (Last Post : auberj - Replies : 0 - Views : 1 )           »          Form split across two columns (Last Post : RICH POW - Replies : 6 - Views : 7 )           »          NetLobo and Hidden
Tags (Last Post : kiusau - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Macromedia Software > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-04-2008, 09:02 AM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Flex FAQ 10/27/08

Amy's Flex Frequently Asked Questions
Q (1): I want to use an XML data source to dynamically display images and
data in my Flex application. I won't know how many images/data points I
will have at design time. How can I best approach this?

A: Depending on what you're wanting to do, you can either use a
Repeater with an Image or custom component that contains an Image or you can
use a List based component to display an Image or custom component with an
Image (or SwfLoader, or Loader) in it. The Help is full of resources on
this subject. Here are some places you may want to try:

Help>Flex Start Page>Creating a Simple RIA
Help>Help Contents>User Interfaces
- Using Data Providers and Collections
- Controls
- Image
- SwfLoader
- Using Data Driven Controls
- Using Item Renderers and Item Editors
- Dynamically Repeating Controls and Containers

Here is an example that might get you running fast if you find it easier to
learn from a working example than from Help files:
http://examples.adobe.com/flex2/inpr...otoViewer.html



Q (2): I've created a custom itemRenderer component to use in a List based
component (Datagrid, TileList, HorizontalList, etc.). When my List first
displays, everything looks fine, but when I scroll it or change the
dataProvider, some of the itemRenderers show values or formatting that
aren't right. How do I fix this?

A: List-based components don't draw a renderer for every item in the
dataProvider. Instead, they create enough to display what is on screen now,
plus one or two more waiting in the wings. This means they recycle the
renderers rather than creating new ones when you change dataProvider or
scroll up and down. When you use a creationComplete event to set up the
itemRenderer, that event doesn't happen again when the renderer is used for
a different set of data. The solution to this is to override the set data
protected function that most components have.

For more information, check out the following resources:
http://www.adobe.com/devnet/flex/art...html?devcon=f1
http://blogs.adobe.com/aharui/2007/0...nderers_1.html



Q (3): I want to run a function in my main application from inside my
custom component. But when I try to refer to myFunction() in that
component, I get a compile time error Call to a possibly undefined function
myFunction. How can I fix this?

A: Your component has its own scope, so it doesn't know anything
about the functions in the main file. You can get around this by directly
referencing the main application scope like this:
Application.application.myFunction(). However, this makes your component
tightly coupled, which is a quick way of saying that your component is only
usable in an application that has a myFunction() function in it. You're
better off dispatching an event from your component and letting the
application decide how to handle it. For more information, check out the
following resources:
http://www.adobe.com/devnet/flex/art..._coupling.html
http://www.adobe.com/devnet/flex/art...ating_pt1.html



Q (4): I want to decide at runtime what kind of component to add to
display my data. How can I accomplish this?

A: Use getDefinitionByName and ClassFactory to dynamically create
your class. Just be sure that you actually have at least one "hard"
reference to each class you intend to use, or the class might not get
compiled into your swf. Here's a full write-up of how to do that:
http://www.paulofierro.com/archives/520/



Q (5): I need to set a property or add an event listener on a component
that is in a ViewStack/TabNavigator/Accordion. When the component is not
the first child of the Navigator Container, I get a null object error
(#1009). What causes this, and how can I fix it?

A: By default, the Navigator containers only create the children of
each pane as that pane is viewed. The easy way to fix this is to set the
creationPolicy on the Navigator to "all." However, this will cause your
application to take longer to load. A better way to fix this is to wait for
a later event, such as creationComplete on the component you want to access,
or to use binding to "pull" the data into the component.
The way I handle it is to call invalidateProperties() on change of the
ViewStack. I then override commitProperties() and call an "initializer" for
each pane. In the body of each initializer function, I check to see if the
selectedItem for the viewStack is the one my initalizer cares about. If
not, I return from the function immediately. Inside that initializer
function, I set properties and add listeners as appropriate.



Q (6): When my application is taller than the browser window, I get
scrollbars in the application. I want the browser to do the scrolling. How
can I do this?

A: In the html-template/index.template.html file change line 46 (in
the Flex 3 template) to read <body scroll="auto"> instead of the default of
<body scroll="no">.



Q (7): I am using URLRequest, HTTPRequest, or HTTPService to retrieve
information from a database on a server. The first time my application
makes a server call, it works fine. But when I call the same page again, I
get the same data, even though I know the data has changed on the server.
Is this a bug?

A: The browser has cached the response it got from the first call
you made to the page. This means that you need to either change how you are
calling the page so it appears to be a new request, or you need to change
the page itself so that it won't be cached.

To change how you are calling the page, append a unique value to the end of
the URL. For example, new URLRequest('yourPage.asp?param="+(new
Date()).getTime).

If you want to change the page itself, you need to change the response
headers. The method for changing the response headers will vary from
language to language. For more on this see:

http://msdn.microsoft.com/en-us/library/aa923184.aspx
http://www.sun.com/books/components/Hall_ch7.pdf
http://www.w3schools.com/php/func_http_header.asp
http://livedocs.adobe.com/coldfusion...7.html#3989067



Q (8): I am using Modules in my Application. When I load the first
Module, everything works fine. But when I load the second one, I get a Type
Coercion Error failed error #1034 that looks something like TypeError: Error
#1034: Type Coercion failed: cannot convert
com.myDomain.package::SingletonClass@fce9a89 to
com.myDomain.package::SingletonClass or TypeError: Error #1034: Type
Coercion failed: cannot convert mx.managers::HistoryManagerImpl@22346589 to
mx.managers.IHistoryManager. How do I fix this?

A: When you reference a singleton class, either a custom singleton
or one of the managers in Flex, into a Module, if this is not loaded in the
Application domain, it will load into the child domain of the first Module
to load and other Modules will not be able to see it. To prevent this,
either directly load your class into the main Application before loading any
Module, or use a Runtime Shared Library with the class included.

For more on this, see Alex Harui's presentation on Modules from Flex 360
http://blogs.adobe.com/aharui/2007/03/modules.html (slides 19, 24-31).

Not sure what a Singleton is? Check out
http://www.adobe.com/cfusion/communi...62&productId=2



Q (9): I'm using a Repeater to lay out the right number of components on
the screen for me based on a data source. I'm trying to set up the id for
each component dynamically like this:

<mx:Repeater id="myRepeater" dataProvider="mySource">
<mx:Button id="{'myButton'+myRepeater.currentIndex}"
label="{myRepeater.currentItem.label}" />
</mx:Repeater>

When I try to run the file, I get a compiler error
'{'myButton'+myRepeater.currentIndex}' is not a valid identifier.

I need to be able to reference each of the repeated components. How can I
do this?



A: If you give the component an ordinary id like this:
<mx:Button id="myButton" label="{myRepeater.currentItem.label}" />
Flex will create an Array for you called myButton that contains a reference
to each component the repeater created. For more information, see
Referencing Repeated Components here:
http://livedocs.adobe.com/flex/3/htm...epeater_3.html



Q (10): I have several components with the ID's "component1", "component2",
"component3", and I want to be able to create a string that contains the
name of the component so I can change a property on that component. How can
I do that?

A: You can refer to any subproperty of an object with a string by
naming the object and then using the string inside brackets. In this case,
you just need to figure out what parent to use, and you can get it working.
Most of the time that you are doing this, the component is in the local
scope, so the parent will be "this". So, to change the width of component1,
you can use this['component1'].width=100.



Q (11): I want to be able to change the icons on my buttons, tree, or
AdvancedDataGrid dynamically, using external assets. How do I do this?

A: The problem with icons in Flex Builder is that they need to be
built from a class file, as discussed here
http://blog.xsive.co.nz/archives/233.
Here are two fixes that may work for you:
http://blog.benstucki.net/?p=42
http://blog.xsive.co.nz/archives/234



Q (12): Where can I find examples of Flex code to look at and/or use?

A: http://code.google.com/p/flexlib/wiki/ComponentList
http://blog.flexexamples.com
http://www.cflex.net
http://www.quietlyscheming.com/blog
http://flexbox.mrinalwadhwa.com/
http://blogs.adobe.com/aharui/
http://www.adobe.com/cfusion/communi...ge&productId=2
http://blogs.adobe.com/flexdoc/



Q (13): I want to set the itemRenderer for my DataGrid, List,
HorizontalList, etc. in ActionScript instead of MXML. How can I do this?

A: When you set the itemRenderer in MXML, Flex creates a
ClassFactory for you under the hood. To set the itemRenderer through code,
you have to create the ClassFactory yourself, like this:
myDataGrid.itemRenderer = new ClassFactory(myRendererClass)
For more about this, see
http://blog.flashgen.com/components/...rendering-pt1/

If you need to set properties on your renderer before you use it, make sure
to implement IFactory.

Not sure why you'd want to set properties on your itemRenderer? Check out
this link:
http://www.returnundefined.com/2006/...h-classfactory



Q (14): I have the following XML
myXML:XML =
<salesData>

<saleDate month="January">

<sales>

<salesPerson>John Smith</salesPerson>

<salesAmount>900</salesAmount>

</sales>

<sales>

<salesPerson>Mary Jones</salesPerson>

<salesAmount>300</salesAmount>

</sales>

</saleDate>

<saleDate month="February">

<sales>

<salesPerson>John Smith</salesPerson>

<salesAmount>600</salesAmount>

</sales>

<sales>

<salesPerson>Mary Jones</salesPerson>

<salesAmount>400</salesAmount>

</sales>

</saleDate>

<saleDate month="March">

<sales>

<salesPerson>John Smith</salesPerson>

<salesAmount>600</salesAmount>

</sales>

<sales>

<salesPerson>Mary Jones</salesPerson>

<salesAmount>700</salesAmount>

</sales>

</saleDate>
</salesData>
When I try to set an XMLList variable to myXML.salesData.saleDate, the
variable is empty, even though when I trace myXML.toXMLString() I can
clearly see that it contains the information I want. What's the problem?

A: Your myXML variable is the entirety of the XML you assigned to
it. So, in essence, the root node, salseData, is the same thing as myXML.
Since salesData does not contain a salesData node, that is why your XMLList
is empty. Try using myXML.saleDate.





Courtesy of Amy's Flex Diary (http://flexdiary.blogspot.com).



The most recent version of this FAQ can always be found at
http://www.magnoliamultimedia.com/fl...s_Flex_FAQ.pdf




Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 09:38 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk