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

**URL:** https://forum.kirupa.com/t/as3-how-can-a-global-var-take-over-a-value-which-appears-in-a-listenerevent/332162
**Category:** flash
**Created:** [February 19, 2014, 1:18pm UTC](https://forum.kirupa.com/t/as3-how-can-a-global-var-take-over-a-value-which-appears-in-a-listenerevent/332162 "2014-02-19T13:18:15Z")
**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, 1:18pm UTC](https://forum.kirupa.com/t/as3-how-can-a-global-var-take-over-a-value-which-appears-in-a-listenerevent/332162/1 "2014-02-19T13:18:15Z")

</div>

So this is what i’m working on:  
I have two calsses: \*\*MINIATURKA \*\*which loads images from url,  
and **MINIATURKI** which loads an XML file and creates an Array of class **MINIATURKA** (loaded jpg)

The problem is, that the img have different widths, and I want to locate all images in a row one next to the another, so the creating of the Array code 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;
}

```

But the problem is that when i trace the \*_mini_.width \*\*it is the same as the this value **[889]** in the code od class \*\*MINIATURKA: buton.graphics.drawRect(0, 0, 889, 500);  
\*\*  
HERE IS THE CODE OD CLASS MINIATURKA:

```auto
[COLOR=#000000]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);
}[/COLOR]

```

[LEFT][COLOR=#000000]I can’t put the creation of button sprite into the sizeHandler function, because the _mini.width_\* will trace as 0 😕  
[/COLOR][COLOR=#000000]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);  
\*\*[/COLOR][COLOR=#000000]Is it even possible?  
[/COLOR][COLOR=#000000]Or is there another way to send the value direct to the another class?

[http://www.adartis.pl/#portfolio](http://www.adartis.pl/#portfolio) - I’m trying to make a universal gallery like on this webside[/COLOR][/LEFT]
