Skip navigation
Currently Being Moderated

How to replace MXML element with another?

Aug 26, 2013 9:08 AM

Tags: #4.5 #actionscript #mxml

Hi. I am pretty new to Flex but I find it very attractive.


What I am trying to achieve is to have two different layouts and initialize them based on the user's choice. Each of these layouts is defined in its own mxml component.


I have two components:

<components:LeftAligned /> and <components:RightAligned />


I could add both in the beginning and have only one visible but I don't want to go down that road. What I tried so far is to have an event handler that replaces the current instance but I hit a wall. Let's say that LeftAligned is the component initialized first and then I want to change it with RightAligned. Now:

  • If I try to replace the lement based on its id: newElement:RightAligned = new RightAligned(); LayoutArea = newElement; I get a implicit coercion error that it can't convert RightAligned to LeftAligned.
  • If I try to removeElement(LayoutArea); addElement(newElement); then I get an exception thrown from other parts of the application that call LayoutArea's methods (event based).

What solutions are there for this? Thank you


More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points