Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 10-25-2006, 09:05 AM   #1
Registered User
Join Date: Oct 2006
Posts: 112
Default Passing variables between MXML files / components - Flex component communication


I am having difficulty with my Flex Application… I don’t know if I am just being stupid and missing / mi-understanding something (which is probably the case) but thing don’t seem to be going my way :(

My application is quite large now, so I will try and explain / include much summarised detail and code examples.

Basically, I have my main MXML File which includes an applicationControlBar containing a linkBar populated using a viewStack as its dataProvider….
The application navigator “links” to other components (MXML files) within the application that are stored in a “components” folder:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:mi="components.*" layout="absolute">

<mx:ApplicationControlBar id="appBar_apc" dock="true">
<mx:LinkBar dataProvider="MenuObjects_lb"/>

<mx:ViewStack id="MenuObjects_lb">

<mi:homePage id="home_page" label="Homepage"/>
<mi:search id="Search" label="Search"/>
<mi:manageUsers id="manage_usrs" label="Manage Users"/>
<mi:viewOPG id="view_OPG" visible="false"/>


The 1st page the user sees is the “Homepage” this page contains a dataGrid that is provided data from a webService – calling the webService and setting up a dataProvider accordingly to populat the dataGrid etc….
The data provided from the dataProvider comes originally from a database and each row contains a unique ID.
The data is displayed in the dataGrid ok, and the ID is assigned ok, and when a row of the dataGrid is selected the correct ID of the selected row is taken – so all is ok to this point:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:mi="components.*">

public function handleWSR(event:ResultEvent):void
myDG.dataProvider = event.result;

public function dgItemSelect():void
selectedID = myDG.selectedItem.id;

<mx:WebService id="wsData" wsdl="http://...?wsdl">
<mx:operation name="getData" result="handleWSR(event)"/>

<mx:Panel id="home_page_test" title="Homepage Test">

<mx:DataGrid id="myDG" change="dgItemSelect()">
<mx:DataGridColumn id="id" dataField="id" headerText="ID"/>
<mx:DataGridColumn dataField="a" headerText="A"/>
<mx:DataGridColumn dataField="b" headerText="B"/>
<mx:DataGridColumn dataField="c" headerText="C"/>
<mx:DataGridColumn dataField="D" headerText="D"/>

<mx:Button id="viewItem" label="View Selected Item" click="????"/>


as you can see – beneath my dataGrid is a button (View) which when clicked I want to take the ID of the selected dataGrid row and pass this ID to another MXML file / component (viewRow.mxml) within my application.
When the “viewRow.mxml” is opened / called I want it to take the ID that was selected from the previous mxml component (the homepage) and use it in another webService call (send the ID to a webService which then uses the ID to retrieve data that is relevant to that ID and thus pass it back to the component) using and displaying the results accordingly…..

Mmmm, I hope that makes sense?

Like I say, I am having great difficulty passing variable from one MXML file to another allowing such dynamic operations – passing and retrieving variables between components (displaying data relevant to a selected ID from another components etc…)
I don’t know if I am doing something wrong (I am quite new to Flex and this is my first “real” Flex application), hence I am asking for some advice, so any suggestions / advice on this would be much appreciated.

ljonny18 is offline   Reply With Quote
Old 10-25-2006, 11:48 AM   #2
Registered User
Join Date: Oct 2006
Posts: 383
Send a message via MSN to CDHBookingEdge

I'm kind of a newbie myself but this might help you. If you use a strategy similar to what is explained here in the Flex help under "Passing Data to and from a popup window" Here's a link to it on the web but it's also in your Help contents. http://livedocs.macromedia.com/flex/...=00000701.html

Another thought is that if your component is a class then you can just put the ID as part of the constructor.

If I'm missing something let me know.

Hope this helps,
CDHBookingEdge is offline   Reply With Quote
Old 10-25-2006, 03:26 PM   #3
Registered User
Join Date: Oct 2006
Posts: 112

Hi Christopher...

I read throught the example in the link you posted - interesting!

it is the sort of thing I am after... but I need / want another MXML component to display / show NOT as a pop up window, but just generally in the application, overriding the current MXML file... (if that makes sense)

where they use the popUp stuff (PopUpManager etc..) I want to just "show" the selected MXML component rather than "pop it up" etc....

do you know of some sort of similar method I can use to just "show" my selected MXML file????

Thanks a lot,
ljonny18 is offline   Reply With Quote
Old 10-25-2006, 08:40 PM   #4
Registered User
Join Date: Oct 2006
Posts: 383
Send a message via MSN to CDHBookingEdge

Yes but really all the popup window is IS another component. So the same techniques can be applied.
CDHBookingEdge is offline   Reply With Quote
Old 10-27-2006, 04:54 PM   #5
Senior Member
Join Date: Aug 2005
Location: Minnesota, USA
Posts: 216

I'm also unsure as to what exactly you want to do, but it sounds to me like you want to use States (not an actual popup browser window?).

You can use States to define ... well, States... of your application. So say you want a login screen to appear (your first State), but then once you've logged in, you want to display your real user interface (a second State).

meddlingwithfir is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Communication Components rhythmofrain Flash Media Server 2 04-19-2005 06:14 AM
Passing variables from external swf files grimm ActionScript 1.0 (and below) 2 02-26-2003 06:27 PM
Creating flash variables from txt files Mathieu_BSL ActionScript 1.0 (and below) 16 08-28-2002 10:34 PM
weird load variables problem between two domains and external .txt files Jessica lucidiastudios ActionScript 1.0 (and below) 9 09-25-2001 06:31 PM
Passing Variables between .swf files april2031 ActionScript 1.0 (and below) 5 06-12-2001 03:16 PM

All times are GMT. The time now is 09:52 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.