In AS2 it was very easy to access any variables from Parents and Childs using _parent or _root .
but after the enhancement that happened to the AS3 the change the way you can access variables from different scops using the timeline Movies or even thru a classes.
****access variables using time line Movies.
to understand how you can access a parent variables from child or vise-versa you need to create new AS3 document and then create Circle Movie and name it "shapes_mc" then inside this Movie Create another square and Movie and name it "square_mc". so finally create a dynamic text name it "name_txt" then converted to movie and name it "textContainer_mc" as in the picture below:
so now on the stage create new variable in farm1 :
var Scope1 = "Scope1"
in the shapes_mc create another variables :
var Scope2 = "Scope2"
in the Square Movie create variable
var Scope3 = "Scope3"
* now I will show you how you can access these variables from different Movies by creating a buttons in each scope and in when the user click will trace the other variables from button scope.
- Stage Button Code :
stage_btn.addEventListener(MouseEvent.MOUSE_DOWN,TraceScopeHandler)
function TraceScopeHandler(e)
{
trace("Stage Variable --> " + Scope1)
trace("Shapes Variable --> " + shapes_mc.Scope2)
trace("square Variable --> " + shapes_mc.square_mc.Scope3)
trace("Text Variable --> " + textContainer_mc.name_txt.text)
}
- shapes Button Code :
var Scope2 = "Scope2"
shapes_btn.addEventListener(MouseEvent.MOUSE_DOWN,TraceScopeHandler)
function TraceScopeHandler(e)
{
var oStage:MovieClip = parent as MovieClip
trace("Stage Variable --> " + oStage.Scope1)
trace("Shapes Variable --> " + Scope2)
trace("square Variable --> " + square_mc.Scope3)
trace("Text Variable --> " + oStage.textContainer_mc.name_txt.text)
}
- square button code:
import flash.display.MovieClip;
square_btn.addEventListener(MouseEvent.MOUSE_DOWN,TraceScopeHandler)
function TraceScopeHandler(e)
{
var oShapes:MovieClip = parent as MovieClip
var oStage:MovieClip = oShapes.parent as MovieClip
trace("Stage Variable --> " + oStage.Scope1)
trace("Shapes Variable --> " + oShapes.Scope2)
trace("square Variable --> " + Scope3)
trace("Text Variable --> " + oStage.textContainer_mc.name_txt.text)
}
----------------------------------
Source Code






