librelist archives

« back to archive

Select a row in DataGrid, no event is dispatched

Select a row in DataGrid, no event is dispatched

From:
Georg Meyer
Date:
2011-10-12 @ 09:33
Hi,

I was wondering, if someone has already solved the following issue:

When I use the Cucumber step to select a row in a Datagrid, it sets the
selectedIndex. But it does not dispatch any events. What I usually do,
is catch these change events on a datagrid, but this does never get
dispatched.

The flex API says the following:

Change: Dispatched when the selectedIndex or selectedItem property
changes as a result of user interaction.


http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/listClasses/AdvancedListBase.html#event:change


So I tried to dispatch this event manually in my step. As far as I know
you can create objects with 

Melomel.create_object(class_name)

But this doesn't take any arguments, so you can't create the respecting
event, which would be something like this in AS:

new mx.events.ListEvent(mx.events.ListEvent.CHANGE)

Well, I'm a bit stuck here. Can anyone help me out?

Thanks,

Georg

Re: [melomel] Select a row in DataGrid, no event is dispatched

From:
Georg Meyer
Date:
2011-10-12 @ 13:35
Hi again,

I found a solution, that (at least) works for me, but it's quite ugly :)

Though, we might use it for a general soultion. I wrote a method in my
topLevelApplication that creates the neccessary event. 

Here's my code:


In my Flex app:

public function createEvent(clazzName:String,type:String):Object{
	switch(clazzName){
		case "mx.events.ListEvent":
			return new ListEvent(type);
			break;
	}
	return null;
}

In my step definition:

app = Melomel.get_class('mx.core.FlexGlobals')
event = app.topLevelApplication.createEvent('mx.events.ListEvent',
'change')
event.rowIndex = index
grid.dispatchEvent(event)



I tried to use Melomel.invoke_function similar to this:

Melomel.invoke_function('flash.utils.getQualifiedClassName', "Some
string.")

But how can I ensure, that melomel has included my class?
I didn't get it to work.

If someone points my to the right files where to put a general solution
to create events, I could implement it and send a pull request.

Georg


Am Mittwoch, den 12.10.2011, 11:33 +0200 schrieb Georg Meyer:
> Hi,
> 
> I was wondering, if someone has already solved the following issue:
> 
> When I use the Cucumber step to select a row in a Datagrid, it sets the
> selectedIndex. But it does not dispatch any events. What I usually do,
> is catch these change events on a datagrid, but this does never get
> dispatched.
> 
> The flex API says the following:
> 
> Change: Dispatched when the selectedIndex or selectedItem property
> changes as a result of user interaction.
> 
> 
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/listClasses/AdvancedListBase.html#event:change
> 
> 
> So I tried to dispatch this event manually in my step. As far as I know
> you can create objects with 
> 
> Melomel.create_object(class_name)
> 
> But this doesn't take any arguments, so you can't create the respecting
> event, which would be something like this in AS:
> 
> new mx.events.ListEvent(mx.events.ListEvent.CHANGE)
> 
> Well, I'm a bit stuck here. Can anyone help me out?
> 
> Thanks,
> 
> Georg
> 

Re: [melomel] Select a row in DataGrid, no event is dispatched

From:
Ben Johnson
Date:
2011-10-12 @ 17:03
George-

Thanks for the fix. The issue with object instantiation is that 
ActionScript doesn't allow you to dynamically instantiate a class with 
variable length arguments. For example, the create_object() code on the 
Flash side goes something like:

var classRef:Class = getDefinitionByName(className);
var obj:Object = new classRef();

You have to know at compile-time how many constructor arguments you're 
passing in. What really needs to be added is separate internal 
createObject() methods for different numbers of arguments that can be 
switched internally like this:

switch(constructorArgs.length) {
  case 0: return createObjectNoArgs(className);
  case 1: return createObject1Arg(className, constructorArgs);
  case 2: return createObject2Arg(className, constructorArgs);
  ...etc
}

That'll require some changes to CreateObjectCommand.as & 
CreateObjectCommandParser.as in the Melomel project.

The step definition change can go in 
lib/melomel/cucumber/data_grid_steps.rb in the Melomel.rb project.

As for the getDefinitionByName(), it should find any class that has been 
linked into your SWF. That means that if you create a class, you have to 
reference it in your code so it'll be compiled into the SWF.


Ben


________________________________
From: Georg Meyer <georg.meyer@oncotest.de>
To: melomel@librelist.com
Sent: Wednesday, October 12, 2011 7:35 AM
Subject: Re: [melomel] Select a row in DataGrid, no event is dispatched

Hi again,

I found a solution, that (at least) works for me, but it's quite ugly :)

Though, we might use it for a general soultion. I wrote a method in my
topLevelApplication that creates the neccessary event. 

Here's my code:


In my Flex app:

public function createEvent(clazzName:String,type:String):Object{
    switch(clazzName){
        case "mx.events.ListEvent":
            return new ListEvent(type);
            break;
    }
    return null;
}

In my step definition:

app = Melomel.get_class('mx.core.FlexGlobals')
event = app.topLevelApplication.createEvent('mx.events.ListEvent',
'change')
event.rowIndex = index
grid.dispatchEvent(event)



I tried to use Melomel.invoke_function similar to this:

Melomel.invoke_function('flash.utils.getQualifiedClassName', "Some
string.")

But how can I ensure, that melomel has included my class?
I didn't get it to work.

If someone points my to the right files where to put a general solution
to create events, I could implement it and send a pull request.

Georg


Am Mittwoch, den 12.10.2011, 11:33 +0200 schrieb Georg Meyer:
> Hi,
> 
> I was wondering, if someone has already solved the following issue:
> 
> When I use the Cucumber step to select a row in a Datagrid, it sets the
> selectedIndex. But it does not dispatch any events. What I usually do,
> is catch these change events on a datagrid, but this does never get
> dispatched.
> 
> The flex API says the following:
> 
> Change: Dispatched when the selectedIndex or selectedItem property
> changes as a result of user interaction.
> 
> 
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/listClasses/AdvancedListBase.html#event:change
> 
> 
> So I tried to dispatch this event manually in my step. As far as I know
> you can create objects with 
> 
> Melomel.create_object(class_name)
> 
> But this doesn't take any arguments, so you can't create the respecting
> event, which would be something like this in AS:
> 
> new mx.events.ListEvent(mx.events.ListEvent.CHANGE)
> 
> Well, I'm a bit stuck here. Can anyone help me out?
> 
> Thanks,
> 
> Georg
>