How do i change an array based on another text field? - actionscript-3

i have a TheList.as class..in which i have created a list for an android app.
Here is TheList.as(Cut down to the specific stuff for this question)
public var _ListItem:ListItem;
public var _Data:Array;
public var _Values:Array;
public var $CurrentValue:String;
public var _TextLabel:TextField;
public function TheList(Data:Array,Values:Array)
{
_Data = Data;
_Values = Values;
initialize();
}
private function initialize():void
{
_TextLabel = new TextField();
addChild(_TextLabel);
_TextLabel.text = "Data";
_Container = new ListContainer ;
addChild(_Container);
_Container.x = 0;
_Container.y = 0;
currentY = _Container.y;
lastY = _Container.y;
for (var i:int = 0; i < _Data.length; i++)
{
_ListItem = new ListItem ;
_Container.addChild(_ListItem);
_ListItem.y = _ListItem.height * i;
_ListItem.addEventListener(MouseEvent.MOUSE_DOWN,onItemDown,false,0,true);
_ListItem.addEventListener(MouseEvent.MOUSE_UP,onItemUp,false,0,true);
_ListItem.mouseChildren = false;
_ListItem.value = _Values[i];
_ListItem.name = _Data[i];
_ListItem.ItemLabel.text = _ListItem.name ;
}
}
Here is the class "TheList" is being used in (Again Cut Down to specific stuff)
$myList = new TheList($Data,$Values);
addChild($myList);
$myList.x = -240;
$myList.y = -203;
$myList.visible = false;
$ListFrom = new TheList($DataFromTo, $ValuesFromTo);
addChild($ListFrom);
$ListFrom.x = -240;
$ListFrom.y = -203;
$ListFrom.visible = false;
$ListFrom._TextLabel.text = $DataFromTo[0];
$ListTo = new TheList($DataFromTo, $ValuesFromTo);
addChild($ListTo);
$ListTo.x = -240;
$ListTo.y = -203;
$ListTo.visible = false;
$ListTo._TextLabel.text = $DataFromTo[0];
Now what i am trying to achieve is that i want to change "$Data" and "$Values" Arrays..as you can see i have a main list and two sublists... when "Time" is selected in the main list, i want the sub-lists to be populated with "Time" related unit names...i tried
if($myList._TextLabel.text == "Time")
{
$ListFrom._Data = ["this", "this", "this" etc]
}
But its not working. I am not getting any error either. I'd really appreciate any help!

What you try to achieve is not pissible in this way. You initialize you lists with data fields. When you reset the data, you need to invalidate your list again. You can achieve this with an item setter
private var __Data:Array;
public function get _Data():Array
{
return __Data;
}
public function set _Data(value:Array):void
{
this.__Data = value;
initialize();
}
make sure that you first cleanup you list before you rebuild it again.
your code:
$ListFrom._Data = ["this", "this", "this" etc]
will automaticly call the setter. A getter and setter method looks like a function but is invoked like a property. means:
object.property = "something" //will call the setter
var something:String = object.property //will call the getter

Related

AS3. MouseEvent click in (for) loop function

am need here onClick one of the movieclip loop_Task.addChild(tee) trace the tee.task_id.text which one is clicked from the list for ex. this
output be like
(List Clicked : 100)
(List Clicked : 101)
or onClick passed the item data it's already clicked to new class screen
here is my code
public function resultHandlerList_items(event:SQLEvent):void
{
// TODO Auto-generated method stub
var result:SQLResult = selectStmt1.getResult();
var numResults:int = result.data.length;
for (var i:int = 0; i < numResults; i++)
{
var row:Object = result.data[i];
var tee:listview_mc = new listview_mc
loop_Task.addChild(tee)
tee.y = 270*i
tee.task_id.text = row.Tid
tee.task_tit.text = row.Ttitles
tee.task_stime.text = row.Stime
tee.task_subject.text = row.Subject
tee.addEventListener(MouseEvent.CLICK, onClickList)
}
function onClickList(e:MouseEvent):void{
trace("List Clicked : " + e.currentTarget)
}
}
in the first thanks to #Organis He give me the way to fix my code and he give me info about how to talk with the compiler with exactly how to make the compiler understand your code this code the fix (e.currentTarget as listview_mc) and now this my code after fixing and i do take a public var String and pass it to other Class
public function resultHandlerList_items(event:SQLEvent):void
{
// TODO Auto-generated method stub
var result:SQLResult = selectStmt1.getResult();
var numResults:int = result.data.length;
for (var i:int = 0; i < numResults; i++)
{
var row:Object = result.data[i];
var tee:listview_mc = new listview_mc
loop_Task.addChild(tee)
tee.y = 270*i
tee.task_id.text = row.Tid
tee.task_tit.text = row.Ttitles
tee.task_stime.text = row.Stime
tee.task_subject.text = row.Subject
tee.addEventListener(MouseEvent.CLICK, onClickList)
}
function onClickList(e:MouseEvent):void{
trace("List Clicked : " + (e.currentTarget as listview_mc).task_id.text)
ts_id = (e.currentTarget as listview_mc).task_id.text;
sport._sport.Remove_Home_Sc(e);
trace("done")
}
}

Actionscript3 how to get the index of object clicked

I'm trying to have this hero shoot the bullet. Ex: The bullet has fire and ice type. if the hero placed is fire type then it will shoot fire bullet, if it's ice type then it will shoot ice bullet. And each bullet have each own effects and damages.
So, I've tried to get the index of hero chosen and later on the index will be used to define which bullet used by tracing (heroesArray.indexOf(heroClicked)); but the value of heroclicked is (object Hero1). so I can't use it since the array of heroesArray is [hero1,hero2]. I did splitting and joining too but it kinda messed up...
My question is how to get the String value that only contains the variable of clicked object (hero1 or hero2)? Is there any 'vocabulary' to get the variable name like getqualifiedclassname used for getting class name of an object?
Or is there any other idea to create bullet type the same as hero type without using indexOf ?
Thanks !
Here is the code :
package {
import flash.display.MovieClip
import flash.events.MouseEvent
import flash.events.Event
import flash.display.Sprite
import flash.utils.*
public class Hero {
private var heroesArray:Array;
private var heroContainer:Sprite = new Sprite;
private var hero1:MovieClip = new Hero1();
private var hero2:MovieClip = new Hero2();
private var bulletArray:Array;
private var bullet1:MovieClip = new Bullet1();
private var bullet2:MovieClip = new Bullet2();
private var moveHero:Boolean = false;
private var movingHero:MovieClip;
private var _money:Money = new Money();
private var _main:Main;
private var _enemy:Enemy = new Enemy(_main);
public function Hero(main:Main)
{ _main = main;
heroesArray = [hero1,hero2];
bulletArray = [bullet1,bullet2];
}
private function playerMoving(e:Event):void
{
if (moveHero == true)
{
movingHero.x = _main.mouseX;
movingHero.y = _main.mouseY;
}
}
private function chooseHero(e:MouseEvent):void
{
var heroClicked:MovieClip = e.currentTarget as MovieClip;
var cost:int = _main._money.money ;
if(cost >= 10 && moveHero == false)
{
_main._money.money -= 10;
_main._money.addText(_main);
moveHero = true;
var heroClass:Class = getDefinitionByName(getQualifiedClassName(heroClicked)) as Class;
movingHero = new heroClass();
heroContainer.addChild(movingHero);
movingHero.addEventListener(MouseEvent.CLICK, placeHero);
}
}
private function placeHero(e:MouseEvent):void
{
var heroClicked:MovieClip = e.currentTarget as MovieClip;
var heroRow:int = Math.floor(_main.mouseY/75);
var heroCol:int = Math.floor((_main.mouseX-10)/65);
if(heroRow>0 && heroCol>0 && heroRow<6 && heroCol<10&&
_main.field[heroRow][heroCol]==0)
{
movingHero.fireRate =75;
movingHero.recharge = 0;
movingHero.firing = false;
movingHero.heroRow = heroRow;
movingHero.x = 42+heroCol*65;
movingHero.y = 10+heroRow*75;
_main.field[heroRow][heroCol]=1;
moveHero = false;
movingHero.removeEventListener(MouseEvent.CLICK, placeHero);
}
}
public function displayHero(stage:Object):void
{
stage.addChild(heroContainer);
for (var i:int = 0; i<2;i++)
{
stage.addChild(heroesArray[i]);
heroesArray[i].x = 37;
heroesArray[i].y = 80+i*70;
heroesArray[i].width=60;
heroesArray[i].height=55;
heroesArray[i].buttonMode = true;
heroesArray[i].addEventListener(MouseEvent.CLICK, chooseHero);
heroesArray[i].addEventListener(Event.ENTER_FRAME, playerMoving);
}
}
}
}
You've pretty much got the answer right in front of you. The two heros are of classes Hero1 and Hero2, and you find the class via
var heroClass:Class = getDefinitionByName(getQualifiedClassName(heroClicked)) as Class;
All you need to do is compare heroClass to those two classes like so:
if(heroClass == Hero1)
{
...
}
else
{
...
}
Linking hero to bullet type
If you don't know, or don't want to learn classes (see my comment for an excellent tutorial) then you'll need a lookup table/Dictionary so that you can link bullet type to hero.
//Put this in your constructor after the bullet types and heroes have been declared
var bulletDict = new Dictionary();
bulletDict[hero1] = bulletTypeIce; //Note the lack of quotations around hero1 and 2
bulletDict[hero2] = bulletTypeFire;
So, to get the bullet type out:
var bulletType = bulletDict[heroClicked];

Adding a dynamically created DataGrid as child or element does not work

I am trying to develop an application in AS3. What I am really trying to achieve is to have only one datagrid and having it show, you say, three different set of datas. (the real count will be changing dynamically, and it does not matter as the problem is not relevant with this) Yes, it has to be only one datagrid because of you know, I need a compact interface.
The class "Sonuc" has three properties which are string versions of inputs from constructor. A typical "Sonuc" object is something like this.
var sonuc1:Sonuc = new Sonuc(1,1,false);
//sonuc1.num = "1"
//sonuc1.type = "1"
//sonuc1.isTrue = "No"
The reason that I have informed you about "Sonuc" class is that I wanted you to know that class was not something too complicated. And x.mxml is the test mxml where I only load the class for testing purposes.
This is what I have coded so far
public class ResultInterface extends UIComponent
{
private const desiredWidth:int = 250;
private const desiredHeight:int = 150;
private const sonuc1:Sonuc = new Sonuc(1,1,false);
public var tablo:DataGrid = new DataGrid();
public var kolonArray:Array = new Array ();
public var sonucArray:Array = new Array ();
public var currentIndex:int = new int ();
public var prevButon:Button = new Button();
public var nextButon:Button = new Button();
public function ResultInterface():void
{
currentIndex = 0;
super();
tablo = new DataGrid();
width=desiredWidth+40;
height=desiredHeight+60;
this.tablo.width = desiredWidth;
this.tablo.height = desiredHeight;
this.tablo.x = 20;
this.tablo.y = 40;
prevButon.x = 10;
prevButon.y = genislik/2 - 10;
prevButon.width =
prevButon.height = 10;
nextButon.x = genislik +20;
nextButon.y = genislik/2 -10;
nextButon.width =
nextButon.height = 10;
var referansColl:ArrayCollection = new ArrayCollection();
sonucArray.push(referansColl);
tablo.dataProvider = sonucArray[currentIndex];
var sampleCol:DataGridColumn = new DataGridColumn();
sampleCol.dataField = "num";
sampleCol.headerText = "Number";
var sampleCol2:DataGridColumn = new DataGridColumn();
sampleCol2.dataField = "type";
sampleCol2.headerText = "Type";
var sampleCol3:DataGridColumn = new DataGridColumn();
sampleCol3.dataField = "isTrue";
sampleCol3.headerText = "Is it true?";
kolonArray.push(sampleCol,sampleCol2,sampleCol3);
tablo.columns = kolonArray;
this.addElement(tablo); //**** this is the problematic line
this.addChild(oncekiButon);
this.addChild(sonrakiButon);
}
public function getNewSonuc(incoming:Sonuc):void
{
sonucArray[currentIndex].addItem(incoming);
}
public function newTablo():void
{
var newTablo:ArrayCollection = new ArrayCollection();
currentIndex = sonucArray.push(newTablo);
}
public function prev(evt:Event):void //I haven't written event listeners yet
{
if(currentIndex > 0)
currentIndex--;
nextButon.enabled = true;
if(currentIndex == 0)
prevButon.enabled = false;
}
public function birSonrakine(evt:Event):void
{
if(currentIndex < sonucArray.length)
currentIndex++;
prevButon.enabled = true;
if(currentIndex == sonucArray.length)
nextButon.enabled = false;
}
in this version, I get a syntax error "call to a possibly undefined method addElement"
I also tried having the base class as "Sprite" and "Canvas"
when I used addChild instead of addElement, then I get runtime error "addChild is not available to this class"
when I just commented the problematic line out, everything was loaded perfectly but the datagrid itself.
Note that error occurs before sending in some data (Sonuc) to datagrid.
and when I tried with canvas and with addelement, I get "Cannot access a property or method of a null object reference" with some weird functions and classes and packages.
1009: Cannot access a property or method of a null object reference.
at mx.styles::StyleProtoChain$/initProtoChainForUIComponentStyleName()[E:\dev\4.y\frameworks\projects\framework\src\mx\styles\StyleProtoChain.as:358]
at mx.styles::StyleProtoChain$/initProtoChain()[E:\dev\4.y\frameworks\projects\framework\src\mx\styles\StyleProtoChain.as:171]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::initProtoChain()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:10926]
at mx.core::UIComponent/regenerateStyleCache()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:10989]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::addingChild()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7465]
at mx.core::UIComponent/addChild()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7162]
at mx.controls.listClasses::ListBase/createChildren()[E:\dev\4.y\frameworks\projects\mx\src\mx\controls\listClasses\ListBase.as:3772]
at mx.controls::DataGrid/createChildren()[E:\dev\4.y\frameworks\projects\mx\src\mx\controls\DataGrid.as:1143]
at mx.core::UIComponent/initialize()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7634]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7495]
at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.y\frameworks\projects\mx\src\mx\core\Container.as:3974]
at mx.core::Container/addChildAt()[E:\dev\4.y\frameworks\projects\mx\src\mx\core\Container.as:2618]
at mx.core::Container/addChild()[E:\dev\4.y\frameworks\projects\mx\src\mx\core\Container.as:2534]
at mx.core::Container/addElement()[E:\dev\4.y\frameworks\projects\mx\src\mx\core\Container.as:2981]
at genel.siniflar::ResultInterfaceArayuz()[C:\Users\Ege\Adobe Flash Builder\brainswift2\src\genel\siniflar\ResultInterface.as:95]
at x()[C:\Users\Ege\Adobe Flash Builder\brainswift2\src\x.mxml:27]
at _x_mx_managers_SystemManager/create()[_x_mx_managers_SystemManager.as:54]
at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\systemClasses\ChildManager.as:311]
at mx.managers::SystemManager/initializeTopLevelWindow()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:3057]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2843]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2723]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\preloaders\Preloader.as:542]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
I really need your help folks, please answer as soon as possible.
Well, I tried calling "addElement" from outside of the constructor, and it worked. However I don't know what did exactly cause this error and I know that my solution is not a legitimate one. And I would like to learn proper solution to this problem.
changes to resultInterface.as
// this.addElement(tablo); **** this is the problematic line, we have commented it out
this.addChild(oncekiButon);
this.addChild(sonrakiButon);
changes to x.mxml
public function onCreationComplete(evt:Event):void
{
showResult.addElement(showResult.tablo);
addElement(showResult);
}

Best way of passing values from a button with as3 event

I develop my own way of doing this simple task. However, I'm now wondering if there is a better way to do it.
The buttons:
var menuBtnEscrit:MovieClip = new MovieClip();
var mbe:btnEscritorio = new btnEscritorio();
menuBtnEscrit.addChild(mbe);
menuBtnEscrit.val = "escrit";
menuBtnEscrit.x = 80;
menuBtnEscrit.addEventListener(MouseEvent.CLICK, novoCont);
dMenu.addChild(menuBtnEscrit);
var menuBtnPublic:MovieClip = new MovieClip();
var mbp:btnPublic = new btnPublic();
menuBtnPublic.addChild(mbp);
menuBtnPublic.val = "public";
menuBtnPublic.x = 244;
menuBtnPublic.addEventListener(MouseEvent.CLICK, novoCont);
dMenu.addChild(menuBtnPublic);
And I can keep going, or create buttons trough some algorithm, and put more properties and take advantage of a MovieClip.
The handler:
private function novoCont(e=null){
if(e!=null) selecCont = new String(e.target.parent.val);
clearDisplay(dSubMenu);
clearDisplay(dConteudo);
var func:String = "cont_"+selecCont;
this[func]();
}
As you can see, there is some common task for all buttons.
If I click the first button, it will call cont_escrit() function. This mechanics works, but it is the best practice? Is there a way of optimize it?
public class BaseButton extends Button {
private var _func:Function;
public function get handler():Function {
return _func;
}
public function set handler(value:Function):void {
_func = value;
}
}
So hero you can create mbe like this
mbe = new BaseButton ();
mbe.hanler = cont_escrit;
The event hanler would be
private function novoCont(e=null){
if(e!=null) {
var selecContent:BaseButton = e.targe as BaseButton ;
var handler:Function = selecContent.handler;
handler();
}
}
Here is an example.
var menuBtnEscrit:MovieClip = new MovieClip();
var mbe:btnEscritorio = new btnEscritorio();
menuBtnEscrit.addChild(mbe);
//menuBtnEscrit.val = "escrit";
menuBtnEscrit.func = this.cont_escrit;
menuBtnEscrit.x = 80;
menuBtnEscrit.addEventListener(MouseEvent.CLICK, novoCont);
private function novoCont(e=null){
if(e!=null) {
var mc:MovieClip = e.target as MovieClip;
var func:Function = mc.func;
func();
}
clearDisplay(dSubMenu);
clearDisplay(dConteudo);
}

Closure problem? - passing current value of a variable

I'm trying to pass the current value of a variable when an a dynamically generated navigation 'node' is clicked. This needs to just be an integer, but it always results in the last node's value.. have tried some different methods to pass the value, a custom event listener, a setter, but I suspect it's a closure problem.. help would be appreciated ;-)
function callGrid():void {
for (var i:Number = 0; i < my_total; i++) {
var gridnode_url = my_grid[i].#gridnode;
var news_category= my_grid[i].#category;
var newstitle = my_grid[i].#newstitle;
var news_content = my_grid[i]..news_content;
var news_image = my_grid[i]..news_image;
var gridnode_loader = new Loader();
container_mc.addChild(gridnode_loader);
container_mc.mouseChildren = false;
gridnode_loader.load(new URLRequest(gridnode_url));
gridnode_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, gridLoaded);
gridnode_loader.name = i;
text_container_mc = new MovieClip();
text_container_mc.x = 0;
text_container_mc.mouseEnabled = false;
var textY = text_container_mc.y = (my_gridnode_height+18)*y_counter;
addChild(text_container_mc);
var tf:TextSplash=new TextSplash(newstitle,10,0,4 );
container_mc.addChild(tf);
tf.mouseEnabled = false;
tf.height = my_gridnode_height;
text_container_mc.addChild(tf);
var text_container_mc_tween = new Tween(text_container_mc, "alpha", Strong.easeIn, 0,1,0.1, true);
gridnode_loader.x = (my_gridnode_width+5) * x_counter;
gridnode_loader.y = (my_gridnode_height+15) * y_counter;
if (x_counter+1 < columns) {
x_counter++;
} else {
x_counter = 0;
y_counter++;
}
}
}
function gridLoaded(e:Event):void {
var i:uint;
var my_gridnode:Loader = Loader(e.target.loader);
container_mc.addChild(my_gridnode);
_xmlnewstarget = my_gridnode.name;
//||||||||||||||||||||||||||||||||||||||||
//when a particular grid node is clicked I need to send the current _xmlnewstarget value to the LoadNewsContent function...
//||||||||||||| ||||||||||||||||||||||||
my_tweens[Number(my_gridnode.name)]=new Tween(my_gridnode, "alpha", Strong.easeIn, 0,1,0.1, true);
my_gridnode.contentLoaderInfo.removeEventListener(Event.COMPLETE, gridLoaded);
my_gridnode.addEventListener(MouseEvent.CLICK, loadNewsContent);
}
function loadNewsContent(e:MouseEvent):void {
createNewsContainer();
getXMLNewsTarget();
news_category = my_grid[_xmlnewstarget].#category;
var tfnews_category:TextSplash=new TextSplash(news_category,20,16,32,false,false,0xffffff );
tfnews_category.mouseEnabled = false;
newstitle = my_grid[_xmlnewstarget].#newstitle;
var tftitle:TextSplash=new TextSplash(newstitle,20,70,24,false,false,0x333333 );
news_container_mc.addChild(tftitle);
tftitle.mouseEnabled = false;
news_content = my_grid[_xmlnewstarget]..news_content;
var tfnews_content:TextSplash=new TextSplash(news_content,20,110,20,true,true,0x333333,330);
news_container_mc.addChild(tfnews_content);
tfnews_content.mouseEnabled = false;
news_image = my_grid[_xmlnewstarget].#news_image;
loadNewsImage();
addChild(tfnews_category);
addChild(tftitle);
addChild(tfnews_content);
var news_container_mc_tween = new Tween(news_container_mc, "alpha", Strong.easeIn, 0,1,0.3, true);
news_container_mc_tween.addEventListener(Event.INIT, newsContentLoaded);
}
I'm not going to try to read your code (try to work on your formatting, even if it's just indenting), but I'll provide a simplified example:
for (var i = 0; i < my_total; i++) {
var closure = function() {
// use i here
}
}
As you say, when closure is called it will contain the last value of i (which in this case would be my_total). Do this instead:
for (var i = 0; i < my_total; i++) {
(function(i) {
var closure = function() {
// use i here
}
})(i);
}
This creates another function inside the loop which "captures" the current value of i so that your closure can refer to that value.
See also How does the (function() {})() construct work and why do people use it? for further similar examples.
Umm, as mentioned above, the code is a bit dense, but I think you might have a bit of type conversion problem between string and integers, is the "last value" always 0? try making these changes and let me know how you get on.
// replace this gridnode_loader.name = i;
gridnode_loader.name = i.toString();
// explictly type this as an int
_xmlnewstarget = parseInt(my_gridnode.name);
// replace this: my_tweens[Number(my_gridnode.name)] = new Tween(......
my_tweens[parseInt(my_gridnode.name)] = new Tween();
Oh and I think it goes without saying that you should massively refactor this code block once you've got it working.
Edit: after further study I think you need this
//replace this: my_gridnode.addEventListener(MouseEvent.CLICK, loadNewsContent);
var anonHandler:Function = function(e:MouseEvent):void
{
loadNewsContent(_xmlnewstarget);
};
my_gridnode.addEventListener(MouseEvent.CLICK, anonHandler);
Where your loadNewsContent has changed arguements from (e:MouseEvent) to (id:String)
Firstly, you do not need to call addChild for the same loader twice (once in callGrid) and then in (gridLoaded). Then you can try putting inside loadNewsContent: news_category = my_grid[int(e.target.name)].#category;instead of news_category = my_grid[_xmlnewstarget].#category; As _xmlnewstarget seems to be bigger scope, which is why it is getting updated every time a load operation completes.