actionscript - Flex access variable from one component into another -


I have a main application in which a variable variable has been declared. I want to use this variable in another component which is present in another package. How can I do this?

The main. Mxml (default package)

  & lt; S: Application xmlns: fx = "http://ns.adobe.com/ Mxml / 2009" xmlns: s = "Library: //ns.adobe.com/flex/spark" xmlns: mx = "Library: // Ns.adobe.com/flex/mx "preinitialize =" foo () "& gt; & Lt; Fx: script & gt; & Lt ;! [CDATA [public var value 1: intestine; Public function foo (): zero {value1 = 5; }] & Gt; & Lt; / Fx: script & gt; & Lt; S: application & gt;  

Comp.mxml (Component Package)

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; S: Group xmlns: fx = "http://ns.adobe.com/mxml/2009" xmlns: s = "library: //ns.adobe.com/flex/spark" xmlns: mx = "library: // Ns.adobe.com/flex/mx "creationcomplete =" foo2 () "& gt; & Lt; Fx: script & gt; & Lt ;! [CDATA [public event foo2 (): Zero {// ------ & gt; Price of access from MXML at 1 here. }] & Gt; & Lt; / Fx: script & gt; & Lt; / S: Group & gt;  

Since the charge you require is in the main application category, you can use the property Are there to access it.

  Main (this page's app). value; // main (application.application) .value; Generally speaking, the correct way to do this is to refer to the source object (in this case, the application) near the caller object - or through some people to pass the value itself. Property. Assume that the  Comp  in the question exists in the main app, you can: 

   gt; & Lt ;! - Comp.mxml: Announce Values ​​as a public variable / property - & gt; & Lt; Fx: script & gt; & Lt ;! [Cdata [public yrr: int; ]] & Gt; & Lt; / Fx: script & gt;  

Comments