# AS3 movieClip access to variables

**URL:** https://forum.kirupa.com/t/as3-movieclip-access-to-variables/228112
**Category:** flash
**Created:** [June 5, 2007, 1:32pm UTC](https://forum.kirupa.com/t/as3-movieclip-access-to-variables/228112 "2007-06-05T13:32:53Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mcv](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@mcv](https://forum.kirupa.com/u/mcv)
#### Post date: [June 5, 2007, 1:32pm UTC](https://forum.kirupa.com/t/as3-movieclip-access-to-variables/228112/1 "2007-06-05T13:32:53Z")

</div>

Hi all,

Like everybody else I have been trying to get my head around Actionscript 3 and the way it works compared to Actionscript 2.  
One thing I am having a major problem with, is accessing from one movie the variables of another movie.

**In ActionScript 2 this problem could be solved like this:**  
\_root.movieClip1.quantity = 10;  
\_root.movieClip2.quantity = 200;

If I was inside movieClip1 and I needed the quantity value from the movieClip2 I could say:  
trace (\_root.movieClip2.quantity);

**In ActionScript 3 I have the following code that I am trying (and works fine):**

_package {_  
_import flash.display.Sprite;_  
_import flash.display.MovieClip;_  
_import flash.events.Event;_  
_import flash.events.MouseEvent;_

_public class test extends MovieClip {_

_public function test() {_  
_init();_  
_}_

_public function init():void {_  
_var button1:MovieClip = new MovieClip();_  
_var button2:MovieClip = new MovieClip();_

_button1.graphics.beginFill(0xFF0000);_  
_button1.graphics.drawRect(100, 100, 100, 15);_  
_button1.graphics.endFill();_  
_button1.quantity = 10;_

_button2.graphics.beginFill(0xFF0000);_  
_button2.graphics.drawRect(300, 100, 100, 15);_  
_button2.graphics.endFill();_  
_button2.quantity = 100;_

_addChild (button1);_  
_addChild (button2);_

_button1.addEventListener(MouseEvent.CLICK, onOverButton1);_  
_button2.addEventListener(MouseEvent.CLICK, onOverButton2);_  
_}_

_public function onOverButton1(event:MouseEvent):void {_  
_trace (event.currentTarget.quantity);_  
_}_

_public function onOverButton2(event:MouseEvent):void {_  
_trace (event.currentTarget.quantity);_  
_}_  
_}_  
_}_

What this does is just tracing the quantity variable for the movie clip you click on.

**My question is what kind of code would I put in the onOverButton1 function to access the quantity variable of button2?**
