# AS3:: How can a global var take a value wich appears in a listenerEvent

**URL:** https://forum.kirupa.com/t/as3-how-can-a-global-var-take-a-value-wich-appears-in-a-listenerevent/332164
**Category:** flash
**Created:** [February 19, 2014, 2:53pm UTC](https://forum.kirupa.com/t/as3-how-can-a-global-var-take-a-value-wich-appears-in-a-listenerevent/332164 "2014-02-19T14:53:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tomeciu](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@tomeciu](https://forum.kirupa.com/u/tomeciu)
#### Post date: [February 19, 2014, 2:53pm UTC](https://forum.kirupa.com/t/as3-how-can-a-global-var-take-a-value-wich-appears-in-a-listenerevent/332164/1 "2014-02-19T14:53:39Z")

</div>

So this is my problem I have two classes:  
First class: \*\*MINIATURKA \*\*which loads all img by **URLRequest**  
Second class: \*\*MINIATURKI \*\*which loads a \*\*XML \*\*file and creates an Array of class **MINIATURKA** (loaded jpg)  
The img have different widths, and i want to place them in a row, one next to the another, so the code of the Array in class \*\*MINIATURKI \*\*should look like this:

```auto
xml1 = new XML(URLLoader(event.target).data);
 var i:Number;
 var currentX:Number = 0;
 mini = new Array(xml1.obrazek.length());            
 count = xml1.obrazek.length();
 for (i=0; i<count; i++)
 {   
     mini* = new Miniaturka(xml1.obrazek*.attribute("id"),i);
     addChild(mini*);
     mini*.x = currentX;
     currentX += mini*.width;
}

```

The problem is that when i trace the mini\*.width value it traces the same value as this value [**889**] in the code of class **MINIATURKA** : **button.graphics.drawRect(0, 0, 889, 500);**  
HERE IS THE CODE OF CLASS MINIATURKA

```auto
public function Miniaturka(id:String, index:Number):void {
    var je:JPGSizeExtractor = new JPGSizeExtractor();
    this.id = id;
    this.index = index;
    tryb = false;
    var loader:Loader = new Loader();
    loader.load(new URLRequest("images/" + id + "m.jpg"));
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, nLoadComplete);
    je.addEventListener( JPGSizeExtractor.PARSE_COMPLETE, sizeHandler);
    je.extractSize("images/" + id + "m.jpg");
    function sizeHandler( e : Event ) : void {
         trace(je.width);
    }
    button = new Sprite();
    button.graphics.beginFill(0x000000, 0);
    button.graphics.drawRect(0, 0, 889, 500);
    button.graphics.endFill();
    button.buttonMode = true;
    addChild(button);
    button.addEventListener(MouseEvent.MOUSE_OVER, onOver);
    button.addEventListener(MouseEvent.MOUSE_OUT, onOut);
    button.addEventListener(MouseEvent.CLICK, onClick);
 }

```

I can’t put the creation of button sprite into the sizeHandler function, because the\*\* mini\*.width **will trace as 0 😕  
The proper value traces the: trace(je.width); from the above code.  
How to make the: **je.width \*\*value work in this line as:** button.graphics.drawRect(0, 0, je.width, 500);**  
Is it even possible?  
Or is there another way to send the value direct to the another class?  
I wan’t to crate a galery like on this website: [http://www.adartis.pl/#portfolio](http://www.adartis.pl/#portfolio)
