?
Solved

Flex : Problem with instantiating an mxml component

Posted on 2010-01-10
3
Medium Priority
?
435 Views
Last Modified: 2013-11-11
I have two mxml files in a flex project: But when I trace a.cBtn, it is null. Why should it be?

test.mxml :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="runIt()">
<mx:Script>
    <![CDATA[
        public function runIt():void
        {
            var a:abc = new abc();
            trace(a.cBtn);//a.cBtn is null here
        }
    ]]>
</mx:Script>    
</mx:Application>

And abc.mxml :
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
    <mx:Button x="108" y="73" label="Button" id="cBtn"/>

</mx:Canvas>
0
Comment
Question by:dtivmk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:vindys80
ID: 26280815
Hi,

Component will be initiated only when you addChild the component into your container.

Thanks,
Vindys
var a:abc = new abc();
				addChild(a);
				trace(a.cBtn);

Open in new window

0
 
LVL 1

Author Comment

by:dtivmk
ID: 26280867
Is there any other way to get it done?
I have some reasons, for which I wouldn't like
to use addChild.
0
 
LVL 11

Accepted Solution

by:
vindys80 earned 2000 total points
ID: 26280887
Hi,

Until createComplete is called in your abc, you won't be able to get cBtn. So it gets called when you add it to your container. Another option will be to add a listener for your abc creation complete and deal with cBtn. I don't feel there is any other option.

Thanks,
Vindys
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to record live broadcast.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question