0

how to use mxml component in another mxml component actionscript code

for ex. in my main mxml file

private var warningMessage:Warning;//this is variable

if (!_controller.flashVars.chatSession || _controller.flashVars.chatSession == "")
            {

                warningMessage.includeInLayout = true;
                warningMessage.visible = true;
            }
            else
            {
                _controller.flashVars.showWarningMessage = "2";
            }

private var warningMessage:Warning;(warning is external custom component)

warningMessage.visible=true (and i want use it like this in my actionscript code

but i am getting error saying "Type was not found or was not compile time constant:warning")

Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

3

There are three things that jump out.

  1. If this component is in another SWC file, make sure to reference it in the project settings
  2. Import the namespace or call it directly (com.whatever.namespace.Warning)
  3. Make sure to call new to generate a new object. In your code above, warningMessage is null.

private var warningMessage:Warning = new Warning();

Brian Genisio
  • 47,787
  • 16
  • 124
  • 167
  • +1. Also, "4. Don't write code in MXML Script section without function - it gets executed as if it was in class constructor, which is too early to manipulate controls - they're not created yet." – alxx May 12 '11 at 05:51
0

Make sure that you have imported your custom component to the file you are using it.

Anji
  • 725
  • 1
  • 9
  • 27
0

You will need to reference the other custom component as a mxml namespace.

Check the following article to get an accurate illustration: http://www.roseindia.net/flex/custom-mxml-tags.shtml

Neeraj
  • 8,408
  • 8
  • 41
  • 69