View Full Version : open MXML component + button click
10-19-2006, 11:08 AM
Summary: open an MXML component from another MXML component on a button click
I have an MXML component within my Flex 2 Application, and within this component I have a button which when clicked, I want to "go / link to" (open) another MXML component.... e.g.:
<mx:button label="open other page" click="open the other MXML component etc..."/>
Additionally I want to be able to pass a variable (on the same button click) to the component that is being opened on the button click, and use this variable within the second component......
Could anyone suggest the best method of going about this?
10-19-2006, 01:45 PM
The architecture of a component isn't quite like a web page, where you'd go from one to the other. Components are part of you application when you compile them, and you determine when and where to instance them within your app at runtime. If guess in this instance, you might be looking for a solution where a user clicks an object in one component, which in turn invokes the display of another component?
The LiveDocs might give you some more pointers: http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=Part3_CreateComps.html
10-19-2006, 03:34 PM
Yes... that is exactly what I want to do! .. :
"where a user clicks an object in one component, which in turn invokes the display of another component"
is this possible (I am sure it is) is there a best method / practive of going about doing this.. I have been reading about "Loosely Coupled Components" and "Broadcasting" / "Triggering" events etc.. dut have had no joy as of yet... am I on the right tracks????
yes, you are right - I need to stop thinking of the flex app as a website... :(
<mx:Button id="button0" label="show panel" click="panel.visible = true"/>
<mx:Panel id="panel" width="100" height="100" visible="false">
that the sort of thing?
as you can see the panel is not visible when its been created. clicking on the button sets its visisble prop to true.
You should also read up on States.
10-25-2006, 03:01 PM
I understand that... but I want to actually display a seperate component (MXML file) that is not related / linked to the current component (MXML file) - if that makes any sense....
when a button is clicked - I want to direct the user to another part of the application... e.g.:
<mx:button label="contact page" click="open / show contact.mxml etc"/>
and when the button is clicked - the contact.mxml is shown etc......
10-25-2006, 08:50 PM
Ok first let's clarify something what is this "component"? I.e.: what type of component is it? Is it another view? Is the view currently visible but empty at the moment or do you want it to come up where the prior view (with the button) is?
I'm guessing from the sounds of it that it's not visible and you want it to appear in the same area as the view that the button existed in. Based on that sounds like you should check into view stacks. Look over some examples where that's used. I think that some looking thru the livedocs and some of the demos will give you some answers to this one.
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.