Dynamic MXML?
Hi,
I have the need to display a different form <mx:Form />
based on a selection in a flex tree control. I have 10 forms in
total, each completely different.
The code is mxml, not actionscript so I am unsure how to do
the if/else logic to change the form to the appropriate one as the
user picks selections from the tree.
This should be easy to do, I know what I want, just not sure
how to achieve it.
I have attached one of the forms. So I need a way of
dynmcially creating this MXML. As you see, the form elements are
hard coded, I want a way to dynamically show different form
elements within a form based on a selection from the tree.
how can this be done? ViewStack with each form as a child?
-Westside
"WestSide" <[email protected]> wrote in
message
news:gisa85$qpv$[email protected]..
> Hi,
>
> I have the need to display a different form <mx:Form
/> based on a
> selection
> in a flex tree control. I have 10 forms in total, each
completely
> different.
>
> The code is mxml, not actionscript so I am unsure how to
do the if/else
> logic
> to change the form to the appropriate one as the user
picks selections
> from the
> tree.
>
> This should be easy to do, I know what I want, just not
sure how to
> achieve it.
Just put them in a ViewStack and switch to the correct "pane"
based on your
logic. I'd use switch/case rather than if-then, but that's
just a matter of
style. Both will work.
HTH;
Amy
Similar Messages
-
Hi,
I am a new comer to flex. I am working on a application proof
of concept where I have to submit a URL to the webserver (end user
will click on a link) and generate the MXML dynamically and display
the output.
I was managed to build it up to the dynamic MXML generation
(using freemarker) and trying to figure it out how send the MXML
text to the compiler to generate the output.
I would greatly appreciate for your help.Yea, and the best of it, FDS is free, for single CPU, a
single "application" and commercial use.
Mark -
Loading MXML Component Dynamically
Hi all,
I am new to Flex and was trying out small things . I created
a MXML Application and also MXML components.
I tried loading MXML component to application using xmlns and
it worked fine.(
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" backgroundColor="#ffffff" xmlns:mi="com.*">
<mi:base1 id="base1" />
<mi:base2 id="base2" />
This method is ok if we are loading 3-4 components .
but , if i have to load a mxml component dynamically how do I
do it?
for example ,if base1 and base2 are two components and i want
to load them based on some event performed.
I have tried the method which uses ViewStack and code
myViewStack.selectedChild=Container(myViewStack.getChildByName(selectedNode))
,where each child will have one component declared or initialized.
Following this method is not a feasible when we have hundred
of components to be loaded.
Can anyone help me on this??"srirama.83" <[email protected]> wrote in
message
news:gpkoui$g3u$[email protected]..
> Hi all,
> I am new to Flex and was trying out small things . I
created a MXML
> Application and also MXML components.
> I tried loading MXML component to application using
xmlns and it worked
> fine.(
> <mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
> layout="absolute"
> backgroundColor="#ffffff" xmlns:mi="com.*">
> <mi:base1 id="base1" />
> <mi:base2 id="base2" />
> )
> This method is ok if we are loading 3-4 components .
> but , if i have to load a mxml component dynamically how
do I do it?
> for example ,if base1 and base2 are two components and i
want to load them
> based on some event performed.
>
> I have tried the method which uses ViewStack and code
>
myViewStack.selectedChild=Container(myViewStack.getChildByName(selectedNode))
> ,where each child will have one component declared or
initialized.
>
> Following this method is not a feasible when we have
hundred of components
> to
> be loaded.
> Can anyone help me on this??
>
>
http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
Q4 -
Dynamic parameter list in a webservice MXML request
Hello,
I'd like to dynamically generate the request parameter of a
web service like that :
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:WebService id="pegasus"
wsdl="
http://myservice?wsdl"
useProxy="false"
load="headers();">
<mx:operation name=" myOperation
">
<mx:request>
<arg0>
<parameter1>{parameter1Input.text}</parameter1>
<parameter2>{parameter2Input.text}</parameter2>
<listParameter3>
<element1>????</element1>
<element1>????</element1>
<element1>????</element1>
<element1>????</element1>
</listParameter3>
</arg0>
</mx:request>
</mx:operation>
</mx:WebService>
So I'd like to know how to generate the list, with an unknown
number of elements, from a datagrid for example.
I tried to generate a XML from a variable like that :
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:WebService id="pegasus"
wsdl="
http://myservice?wsdl"
useProxy="false">
<mx:operation
name="myOperation">
<mx:request>
<arg0>
<parameter1>{parameter1Input.text}</parameter1>
<parameter2>{parameter2Input.text}</parameter2>
<listParameter3>
{myList}
</listParameter3>
</arg0>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:Script>
<![CDATA[
public var myList:XML;
public function essai():XML {
// call this function before send
// populate myList from formulary
]]>
</mx:Script>
But it didn't work, can you help me ?This current problem with the forum makes code almost
impossible to read. Hope they fix it soon.
You can build the request object in AS code. Use mxml to
declare the webservice. Then in a function do something like this
example:
//Sets up and invokes werservice call
private function getEmployees():Void
var sOperationName:String = "getList";
//Put the operation name in a var
var oRequest:Object = employeeWS[sOperationName].request;
//get a reference to the operations request object
oRequest.deptId = dept.selectedItem.data; //put the deptId
Name/Value pair in the request
var call = employeeWS[sOperationName].send(); /Invoke the
call
Tracy -
Dynamically add custom MXML components in Actionscript
As there's no constructor for custom MXML components, how to
dynamically add it as a child using ActionScript?
I'm looking for some alternative to avoid the need to rewrite
the entire existent component in ActionScript just to add it this
feature (a constructor). PopManager is not an alternative...
Is there any way?
The case/situation:
I have a custom MXML component that needs to be dinamically
added to a NativeWindow created using ActionScript.
Thanks a lot!
Vicente Junior
Independent Web Developer
http://teclandoalto.blogspot.commxml classes get generated into AS classes with a default
constructor.
In fact, there is essentially no difference between an AS
component and an mxml component, they can be used exactly the same
way.
Tracy -
Convert mxml to swf dynamically?
I am new to Flex. I'm trying to do something, but I am not
sure if this apporach could even be possible.
1. I have virtual books, and each book is implemented as mxml
(as a seperated application).
2. I have another main flex application, which will try to
retrieve the virtual book as xml (mxml is merely a xml document..)
using HttpService or webservice, and render it.
Is it possible for the virtual book to be compiled
dynamically and run inside the main app? AIR might play a role for
this? This approach makes sense at all?
What I want to do is .. I write the main app ONCE, and
display(render) the books dynamically. Would anybody advise me what
I can do for this?
Thanks,
LeeThanks Tracy. I'd like to ask question on your reply.
"It is possible to compile mxml on the fly,"
- how do we accomplish this?
"but that is not the way to go with this issue."
- if I can compile the book mxml on the fly, and run it
within my application, I don't need to create a compont and parse
xml (book mxml). Isn't this true? why can't this this option be my
solution??
Thanks again,
lee -
Dynamic app creation using MXML?
I'm working on creating a small quiz application which will
be driven by pre-formatted external XML. I have designed various
custom question canvases for each of the question types (MCQ, short
answer, match-pairs etc.) and I'm wondering if there is some way to
implement the main application using MXML instead of ActionScript?
I've managed to hard-code the order of the questions, knowing
which canvases are needed in which order, but I need to be able to
detect the question type from the XML (that bit I can manage) and
then add the appropriate question canvas component in order in my
tabNavigator.
Essentially, I'm trying to replicate the function of a
switch:case clause in MXML. Does anyone know if this is possible?
I've started trying to implement it in ActionScript, but I'm a bit
of a newbie to AS3, and I keep getting errors I don't understand,
like "Access of undefined property" where I'm referring to an
object I've just declared and instantiated in the previous line of
code. E.g (anywhere I use mainPanel):
<mx:Script>
<![CDATA[
import mx.controls.Text;
import mx.containers.Canvas;
import mx.containers.Panel;
var mainPanel:Panel = new Panel();
Root.addChild(mainPanel);
mainPanel.layout = "absolute";
mainPanel.setStyle("left", 10);
mainPanel.setStyle("top", 10);
mainPanel.setStyle("right", 10);
mainPanel.setStyle("bottom", 10);
var testPage:Canvas = new Canvas();
var numQuestions:int = quizQns.childNodes.length;
var qTypes:Array = new Array(numQuestions);
var textLine:Array = new Array(numQuestions);
]]>
</mx:Script>You can declare and initialize variables outside functions in
your script block, but for most else you need to do it in a
function. I would continue learning AS3 as it will give you real
flexibility and power.
<?xml version="1.0"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Text;
import mx.containers.Canvas;
import mx.containers.Panel;
private var mainPanel:Panel;
private var testPage:Canvas = new Canvas();
private var numQuestions:int = 10;
// private var numQuestions:int = quizQns.childNodes.length;
private var qTypes:Array = new Array(numQuestions);
private var textLine:Array = new Array(numQuestions);
public function init():void {
mainPanel = new Panel();
addChild(mainPanel);
mainPanel.layout = "absolute";
mainPanel.setStyle("left", 10);
mainPanel.setStyle("top", 10);
mainPanel.setStyle("right", 10);
mainPanel.setStyle("bottom", 10);
]]>
</mx:Script>
</mx:Application> -
Dynamic addition of MXML Component
Is it possible to add an MXML component through an ActionScript.
I have a situation where I display multiple checkboxes and on click of each I show a subform. I am planning to make that subform as MXML component and add/remove it based on the user's checking/unchecking the checkbox..Is this possible?
Thanks
DharmeshHi Ben ..
Appreciate your quick response. This is my first Flex app. In a nut sheel here is a sample similar to what I am trying to achieve.
Consider my Mxml component as follows
<?xml version="1.0" encoding="utf-8"?>
<!-- myComponents/TempComponent.mxml -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Button label="Hey there from component"/>
</mx:Canvas>
Now here he my app mxml file
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:temp="mycomponents.*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function addRemove():void{
//How do i add that component to the Panel?
]]>
</mx:Script>
<mx:Checkbox id="cb" change="addRemove()" label="Check or Uncheck"/>
<mx:Panel id="testPanel" x="0" y="0" width="100%" height="200" layout="absolute" borderThickness="0" borderThicknessBottom="0"/>
Can you guide me what should go in the listener to add the component to the panel? -
Hi ,
Static Object Creation :
Eg:
<mx:Fade id="ViewStack_EffectStart" duration="500" alphaFrom="0.0" alphaTo="1.0"/>
<mx:Fade id="ViewStack_EffectEnd" duration="500" alphaFrom="1.0" alphaTo="0.0"/>
<comp:ErrorBox id="errorBox" active="{active}" showEffect="{ViewStack_EffectStart}" hideEffect="{ViewStack_EffectEnd}"/> .
The above static objects is working fine, but the problem is that we have lot of similiar static object which creates a memory issue.If we create dynamic objects, will it avoid the issue.Is dynamic objects advisible?.
Thanks in advance.Please reply ASAP.
Thanks ,
San.hmn.. I don't understand your questions fully.
What about create the fade object in "Model" and reference the same Fade object for all dynamic objects?
or r u asking to find out how to create fade in actionscript?
var fade:Fade = new Fade();
fade.target = this;
fade.alphaFrom = 0;
fade.alphaTo = 1;
fade.play();
hope this helps,
BaBo, -
Import mxml/dynamic markup?
I am a relative newcomer to flex and am slowly getting my head around developing flex apps. My question is...
Is it possible to import mxml markup from xml/text? For example, can you have a text/xml file with
<mx:Text text="Some Text"/>
<mx:Text text="Some More Text"/>
Then from your flex app import that and insert it as actual mxml elements on the fly? Hope that made sense.
Cheers.Actually nope, mxml markup is used on compile time only, after you've got a build you could use .swf modules to load external functionality.
http://livedocs.adobe.com/flex/3/langref/mx/modules/ModuleLoader.html -
Dynamic and inherited States in MXML not recognized
Hi ! can you explain how Flash Builder detects the states in MXML?
It seems that it only parses the inline MXML declaration (and only strings!)
<s:states>
<s:State name="state1"/>
<s:State name="state2"/>
</s:states>
but if you have states defined in the base class those states are not recognized when you type includeIn, excludeIn, etc.
Even more ! if you make something like this:
<s:states>
<s:State name="{STATE_NAME}"/>
<s:State name="state2"/>
</s:states>
Where STATE_NAME is a local var, Flash Builder doesn't recognize it either.
Please tell me if this is a bug or a lack of feature, and in any case, if there is a workaround for this.
I need to inherits my states, and use them in the child components.
Thanks !
Enrique.but problem is when I try to set some variable as valie of
attribute and I dont want to make it bindable: I get warnings
unable to bind,etc etc ....
so I am pretty sure it tries bind anything that is variable
type. for example I have static variable :
static public var MY_DATE_RANGE: Object = {rangeStart : new
Date(1970,0,1), rangeEnd : new Date()}; and if I set that as value
of attribute selectableRange of DateField component :
selectableRange="{NpdNaDateField.UNLIMITED_DATE_RANGE}"
I start getting warnings : unable to bind etc etc ... so that
means it is trying to bind.
but how else I can set that value besides {}?
if I do
selectableRange="NpdNaDateField.UNLIMITED_DATE_RANGE" does
not work. -
Dynamic Generation of MXML code
I have a flex application which loads another sub-application.
The parent application has tools which allows the user to add a component to the sub-application and modify some of the component's properties (for eg. when the user clicks on the text box tool in the parent application, a text area component gets added to the sub-application).
Now how can I modify/create-new mxml code for the sub-application reflecting the additions made by the user at runtime?
(This application somewhat immitates what a user gets to do in the design mode in flash builder where the mxml code gets generated behind the scenes. So can I make use of flash builder by implementing some of its methods or extending its classes etc to get the job done?)Its true that mxml is just a conveniant notation and that's why I feel it is suitable for what I intend to do. All what is really being done here is to save the state of the sub-application swf so that it can be edited again later. So a conveniant notation is exactly what it needed.
For this I do have to create MXML on the fly. However there is no real need to compile it at the same time. This is because running the sub-application would already be a visual representation of the modified mxml, although I do realize that it is not the compiled version of the modified mxml. This would work assuming that the modifications made to the sub-application at runtime translate accurately into mxml to the extent that there would be no difference between the currenlty playing swf file and the compiled swf of the modified mxml. This process would also eliminate the need for repetitive compilation which can ultimately be done once the user chooses to save the changes. -
Using Flex 2 for dynamic creation of a Flex 2 application at runtime
We're looking to replace our existing end-user development
environment and believe Flex 2 may be able to satisfy our
requirements. However, without spending a month trialing the
product I thought some existing user(s) could suggest (based on
personal experience) whether we'd be straining Flex 2 in expecting
it to be able to provide dynamic runtine generation and execution
of an application based on the meta-data associated with each
component. The generation of each component includes automatic form
and code generation, with end-user tailoring facilities to maintain
the meta-data (tabs, fields (visibility, location, business rules,
actions, validation etc.), display format, drill-down, work-flow
etc.), for use in the next instantiation of each conponent.I know of at least one of our customers (not sure if I can
say which) is doing this. They use Flex to compose MXML files and
then send that to a server. The server than compiles that into a
SWF.
So it is possible, just a lot of work. -
New way to do Dynamic Icons in Flex
Hi All,
I figured out another way to make dynamic icons in Flex:
Flex Code:
In the container mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
paddingLeft="2" paddingRight="2" horizontalGap="2">
<mx:Script>
<![CDATA[
import mx.core.Application;
[Bindable]
[Embed(source="common/swf/dynamicIcon.swf") ]
public var isDynamicIcon:Class;
]]>
</mx:Script>
<mx:Image id="ico_mag_sm" source="{isDynamicIcon}" />
<mx:Spacer width="1"/>
<mx:Text id="_name" text="{data.ApplicationName}"
paddingLeft="5" selectable="false"/>
</mx:HBox>
In the Applicaton mxml:
<mx:Script>
<![CDATA[
i// ActionScript file
import inc.ApplicationProperties;
//NOTE: do NOT type the commonPath variable. Typing it to String breaks the code.
public var commonPath = ApplicationProperties.COMMON_PATH;//this is the url to the server where the icons are located.
]]>
</mx:Script>
dynamicIcon.swf AS 3.0 code:
stop();
var iconFolder:String = "inc/icons/";
var parentArray:Array = new Array();
//find the highest display container
function getIconName(myObject){
while (myObject.parent){
myObject = myObject.parent;
var topParent = myObject;
var objectName:String = myObject.name;
parentArray.push(objectName);
// for some reason I can't just set the iconName equal to the myObject.name. The only way I could get it to work is to push
//it onto an array first and then access it in the array.
for(var i:Number=0;i<parentArray.length; i++){
if(parentArray[i].indexOf("ico_")==0){
var iconName:String = parentArray[i];
break;
var myURL:String = topParent.getChildAt(0).application["commonPath"];
var loadPath:String = myURL+iconFolder+iconName+".png";
var loadit = new Loader();
addChild(loadit);
loadit.load(new URLRequest(loadPath));
getIconName(this.parent);
BUT, I am new to Flex and AS 3.0 and I know this code is uglier than it needs to be and have the following two issues.
1) In the AS 3.0 code, to determine the parent application, I should be able to just reference the parent application directly rather than have to iterate through .parent. Since I am using the Image tag and not using a loader, the only way I could figure out how is to iterate thought .parent. Is there a more direct way to get the parent or more specifically, the COMMON_PATH attribute of the ApplicationProperties class?
2) In the AS 3.0 code, for some reason, I could not just stick the retrieved myObject.name in into the iconName variable and add it to the URL string. Just out of desperation, I pushed it onto an array first and then accessed it and it worked.
Anyone got any ideas on either or both item 1 or 2 above?
TIA,
SteveI should have been more clear. This largely based on I am Link's method to create dynamic icons in a datagrid:
http://blog.tygate.com/?p=359
I just took it a step further. -
Using Repeater to generate dynamic line charts
I have a call to a webservice that returns an array of
arrays. The outside array relates to the "YEAR", and the inside
arrays have 1 element for each "MONTH". I want to create a line
chart that has a line for each year, with the x-axis having months
across the bottom.
I can create this just fine by coding the appropriate number
of mx:LineSeries tags in my code.
However, I have a case where the data that I get back from
the webservice could have up to 5 years (I'm only coding for 3).
So, I'd like to find a way to dynamically generate an mx:LineSeries
instance for each one of these years. I can't seem to get this to
work with using a Repeater.
This code isn't mine (got it from the docs), but it matches
with what i'm trying to do exactly:
<?xml version="1.0"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml">
<mx:Script><![CDATA[
import mx.charts.events.ChartItemEvent;
import mx.collections.ArrayCollection;
[Bindable]
public var expenses_2005:ArrayCollection = new
ArrayCollection([
{Year: 2005, Expense: "Taxes", Amount: 2000},
{Year: 2005, Expense: "Gas", Amount: 100},
{Year: 2005, Expense: "Food", Amount: 200}
[Bindable]
public var expenses_2006:ArrayCollection = new
ArrayCollection([
{Year: 2006, Expense: "Taxes", Amount: 2500},
{Year: 2006, Expense: "Gas", Amount: 400},
{Year: 2006, Expense: "Food", Amount: 300}
[Bindable]
public var expenses:ArrayCollection = new ArrayCollection([
expenses_2005,
expenses_2006
]]></mx:Script>
<mx:LineChart dataProvider="{expenses}"
showDataTips="true">
<mx:horizontalAxis>
<mx:CategoryAxis dataProvider="{expenses.getItemAt(0)}"
categoryField="Expense" title="Expense"/>
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:LinearAxis displayName="Amount"/>
</mx:verticalAxis>
<mx:series>
<mx:LineSeries xField="Expense" yField="Amount"
displayName="2005" dataProvider="{expenses.getItemAt(0)}"/>
<mx:LineSeries xField="Expense" yField="Amount"
displayName="2006" dataProvider="{expenses.getItemAt(1)}"/>
</mx:series>
</mx:LineChart>
</mx:Application>
How can I now change this to dynamically build the necessary
numbers of LineSeries?Hi jsevlie,
What I usually do in this case is to create multiple
LineSeries objects in ActionScript as soon as I get in the data.
Here is some code to get you started:
private var theChart:ColumnChart = new ColumnChart;
function drawGraph(){
this.theChart.dataProvider = this.theData;
var ctgAxis:CategoryAxis = new CategoryAxis();
ctgAxis.dataProvider = this.theData;
ctgAxis.categoryField = "0";
this.theChart.horizontalAxis = ctgAxis;
var series:Array = new Array();
for(var i:int=0; i < this.columnSpan; i++){
var colSeries:ColumnSeries = new ColumnSeries();
colSeries.yField = String(i+1);
if(i==0){
colSeries.displayName = "Revenue";
colorSrs(colSeries, 0x3F48F3);
else if(i==1){
colSeries.displayName = "Profit";
colorSrs(colSeries, 0xE9C836);
else{
colSeries.displayName = "Cost";
colorSrs(colSeries, 0x6FB35F);
series
= colSeries;
this.theChart.series = series;
Maybe you are looking for
-
FBL1N - Vendor Line item display
Hi, In Transaction FBL1N in line lay out I can see the column Asset no and Sub No are exist, but when I check for asset acquisition transactions asset no is not showing in asset column. How can we bring the asset no and sub no for asset transactions.
-
Follow-up material being assigned to another follow-up material
Hi, I am trying to assign a follow-up material A to material B but get the following message: Material B is already a follow-up material in plant X. This is not a warning or an error message but I still can't save the changes. I have tried to search
-
Hi Guru's, After Billing, two Accounting documents will be generated. Where do we configure for these documents to be generated and how? Som times only one Accounting document is getting generated And the other document is not getting generated. Why?
-
Need to link menu buttons ?
OK, so as you can see i have home, games, hardware ect, I want to link them to... index.html /games /hardware /accessories /outlet /contact Im new to flash and im really having trouble can you do it for me or explain what i need to do, please view my
-
Midp 2.0 cant play sounds properly
still having trouble with the midp sound player thing - see my recent post on sound. I guess the summary is: do you create and keep a different Player for each type of sound, or do you have only one Player which has to go through the realize()->prefe