I ran your code and it worked fine, except for one thing:

The reference to the “press” method was not quite right.  I changed it from this:

tview.press();     //this would require a press method at the application level

 

To this:

tview.tna.press();            //this runs the method on the sub-component

 

You could also do as you began, but passing in a reference to one subcomponent into the other:

<testouttwo id="tnaa" tview="{this}" tna="{tna}"/>

public var tna:Object;      //this would work, but you did not pass the reference in yet, like this:

 

 

One more recommendation, Where you are passing a reference to a subcomponent, be sure to data “type” it specifically.  So

public var tna:Object; should be public var tna:testoutone

 

and public var tview:Object; should be public var tview:MyMainMxmlFileName;

 

This will ensure that you can bind properties in the subcomponent to values at the application level.

 

So, did something not work for you?

Tracy

 


From: [email protected] [mailto:[email protected]] On Behalf Of Tracy Spratt
Sent: Tuesday, September 20, 2005 12:37 PM
To: [email protected]
Subject: RE: [flexcoders] Communication betwen two .as files

 

Breaking up code into components like that is good practice.  It will be easier to maintain and it will help avoid the 32k issue. 

 

At first look the code seems ok.  I’ll try to run it and see if I see anything.

 

Tracy

 


From: [email protected] [mailto:[email protected]] On Behalf Of [EMAIL PROTECTED]
Sent: Tuesday, September 20, 2005 11:27 AM
To: [email protected]
Subject: [flexcoders] Communication betwen two .as files

 

How do you have an mxml file that has two .as files and one .as file has a function in it that calls the method in the other .as file. Let me show you what I want to do, here is the mxml file What I want to do is to have someone press the testouttwo button then have it call the acivatetwo() method in testouttwo which in turn calls the press method in testout one. Is this possible to do? I know an mxml file with two .as files is not neccessary I am just wanting to learn to handle it because I ran in to the 32k error.:

<?xml version="1.0" encoding="utf-8"?>

 

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*" width="550">
<testoutone id="tna"  tview="{this}"/>
<testouttwo id="tnaa" tview="{this}"/>
 <mx:HBox id="help" visible="true">
<mx:Button label="testoutone" id="turnon" click ="tna.activate()"/>
<mx:Button label="testouttwo" enabled = "true" id="turnontwo" click ="tnaa.activatetwo()"/> 

 

</mx:HBox>
<mx:HBox>
<mx:Button label="connect" enabled = "true" id="connect" />
</mx:HBox>
</mx:Application>

 Here is the first .as file

class testoutone {
 public var tview:Object;
  

 

    function testoutone() {
     
    }

 

    public function activate(){
tview.turnon.label="YES"

 


}
 public function press(){
tview.connect.label="YES"

 


}
}

Now here is the second .as file

class testouttwo {

 

    public var tview:Object;
public var tnaa:Object;
    function testouttwo() {
     
    }
 public function activatetwo(){
tview.turnontwo.label="YES"
tview.press()

 

}
   

 

}





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to