I must admit I’m totally lost as to
what you’re trying to do. Can you reduce the example down? All the
import statement does is allow you to not fully qualify your classnames, it isn’t
needed to actually bring in the class nor will it provide a reference.
Generally you pass a reference of one
instance to another by setting a variable directly or passing it as a parameter
to a method. Nothing really more to it. Using binding to assign the value is
a fine way to do it too.
Matt
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Monday, April 11, 2005 12:10
PM
To: [email protected]
Subject: [flexcoders] question
about the import statement and action script files
Just so you all know I am just starting out with flex so I
am really new to this. What I am trying to do is have two action script files
communicate with eachother by having one know what the value of a variable is
in the other. The code I am going to show you is something that could have been
done with a simple mxml file but I was making it this way because I want to
learn how to get two action script files to know what the value of a variable
is. In a nutshell what the program is supposed to do is to have an array of
buttons and the users a button on the top and the button on the bottom and then
have the product appear in the third box. Here is the code for the mxml file
named simplebuttonlist.
<?xml version="1.0"
encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*">
<simplebuttonlistasone id="slone" sView="{this}"/>
<simplebuttonlistastwo id="slonetwo"
sViewtwo="{this}"/>
<mx:HBox id="numberholder" visible="true">
<mx:Button id="onebutton" label="1"
click="slone.numberbuttonone()"></mx:Button>
<mx:Button id="twobutton" label="2"
click="slone.numberbuttontwo()"></mx:Button>
<mx:Button id="threebutton" label="3"
click="slone.numberbuttonthree()"></mx:Button>
<mx:Button id="fourbutton" label="4"
click="slone.numberbuttonfour()"></mx:Button>
<mx:Button id="fivebutton" label="5"
click="slone.numberbuttonfive()"></mx:Button>
<mx:Button id="sixbutton" label="6"
click="slone.numberbuttonsix()"></mx:Button>
<mx:Button id="sevenbutton" label="7"
click="slone.numberbuttonseven()"></mx:Button>
<mx:Button id="eightbutton" label="8"
click="slone.numberbuttoneight()"></mx:Button>
<mx:Button id="ninebutton" label="9"
click="slone.numberbuttonnine()"></mx:Button>
<mx:Button id="tenbutton" label="10"
click="slone.numberbuttonten()"></mx:Button>
</mx:HBox>
<mx:HBox id="numberholdertwo" visible="true">
<mx:Button id="onebuttontwo" label="1"
click="slone.numberbuttoneleven()"></mx:Button>
<mx:Button id="twobuttontwo" label="2"
click="slone.numberbuttontwelve()"></mx:Button>
<mx:Button id="threebuttontwo" label="3"
click="slone.numberbuttonthirteen()"></mx:Button>
<mx:Button id="fourbuttontwo" label="4"
click="slone.numberbuttonfourteen()"></mx:Button>
<mx:Button id="fivebuttontwo" label="5"
click="slone.numberbuttonfifteen()"></mx:Button>
<mx:Button id="sixbuttontwo" label="6"
click="slone.numberbuttonsixteen()"></mx:Button>
<mx:Button id="sevenbuttontwo" label="7"
click="slone.numberbuttonseventeen()"></mx:Button>
<mx:Button id="eightbuttontwo" label="8"
click="slone.numberbuttoneightteen()"></mx:Button>
<mx:Button id="ninebuttontwo" label="9"
click="slone.numberbuttonnineteen()"></mx:Button>
<mx:Button id="tenbuttontwo" label="10"
click="slone.numberbuttontwenty()"></mx:Button>
</mx:HBox>
<mx:HBox>
<mx:Button label="make number appear"
click="slonetwo.fillinanswer()"/>
</mx:HBox>
<mx:HBox><mx:Label text="first number" />
<mx:TextInput editable="false" width="30" id=
"numberone" /><mx:Label text="times second
number" />
<mx:TextInput editable="false" width="30"
id="numbertwo" />
<mx:Label text="=" />
<mx:TextInput editable="false"
id="numberthree" width="30" />
</mx:HBox>
</mx:Application>
There is also an action script file saved as
simplebuttonlistasone
// ActionScript Document
class simplebuttonlistasone
{
public var thefirstnumber:Number
public var thesecondnumber:Number
public var thethirdnumber:Number
public var sView:Object;
public function simplebuttonlistone()
{}
public function numberbuttonone(){
thefirstnumber=1
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttontwo(){
thefirstnumber=2
sView.numberone.text =String(thefirstnumber)
public function numberbuttonthree(){
thefirstnumber=3
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttonfour(){
thefirstnumber=4
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttonfive(){
thefirstnumber=5
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttonsix(){
thefirstnumber=6
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttonseven(){
thefirstnumber=7
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttoneight(){
thefirstnumber=8
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttonnine(){
thefirstnumber=9
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttonten(){
thefirstnumber=10
sView.numberone.text =String(thefirstnumber)
}
public function numberbuttoneleven(){
thesecondnumber=1
sView.numbertwo.text =String(thesecondnumber)
public function numberbuttontwelve(){
thesecondnumber=2
sView.numbertwo.text =String(thesecondnumber)
}
public function numberbuttonthirteen(){
thesecondnumber=3
sView.numbertwo.text =String(thesecondnumber)
}
public function numberbuttonfourteen(){
thesecondnumber=4
sView.numbertwo.text =String(thesecondnumber)
}
public function numberbuttonfifteen(){
thesecondnumber=5
sView.numbertwo.text =String(thesecondnumber)
}
public function numberbuttonsixteen(){
thesecondnumber=6
sView.numbertwo.text =String(thesecondnumber)
}
public function numberbuttonseventeen(){
thesecondnumber=7
sView.numbertwo.text =String(thesecondnumber)
}
public function numberbuttoneightteen(){
thesecondnumber=8
sView.numbertwo.text =String(thesecondnumber)
}
public function numberbuttonnineteen(){
thesecondnumber=9
sView.numbertwo.text =String(thesecondnumber)
}
public function numberbuttontwenty(){
thesecondnumber=10
sView.numbertwo.text =String(thesecondnumber)
}
Also an action script file that figures the answer of the
mathematical problem called simplebuttonlistastwo
/ ActionScript Document
import simplebuttonlistasone
class simplebuttonlistastwo
{
public var thefirstnumber:Number
public var thesecondnumber:Number
public var thethirdnumber:Number
public var sViewtwo:Object;
public function simplebuttonlistastwo()
{}
public function fillinanswer(){
var simplebuttonlist:simplebuttonlistasone = new
simplebuttonlistasone();
thethirdnumber =thefirstnumber*thesecondnumber
sViewtwo.numberthree.text =String(thethirdnumber)
}
}
I tried the import statement thinking it would help but all
that happens when I try to get the answer is a NaN
in the answer. How do I import the number values from simplebuttonlistasone to
simplebuttonlistastwo without having to redefine them. I want to learn how to
do this in case my action script files get too large this is why I am asking.
Yahoo! Groups Links