[flexcoders] Re: Java-like equals() method?
Thanks for the replies. Well, Jitendra's solution worked only when I created a ComboBox subclass that did take a special equals() (based on the value of a property named id) into account. Basically, I overrode the selectedItem property in this subclass. I think equals() and hashCode() are absolutely important, and I find that it's a pain that Flex doesn't have them: In collection contains() methods, selecting items in controls, etc., an equals() semantic is really important. There are many duplicate objects that are semantically equivalent in RIA clients, and without well-defined semantics for equality I'm finding that I have to implement this sort of logic in components myself. Any chance that this may be addressed in forthcoming Flex versions? Thanks, -- Frank --- In flexcoders@yahoogroups.com, Maciek Sakrejda [EMAIL PROTECTED] wrote: Frank, There's no .equals() in actionscript unless you implement it yourself. Without hearing more about the context, it's hard to tell whether Jitendra's data binding solution would work for this specific problem (data binding would effectively set the list selection to an object that is not in the list--I'm not sure what happens there), but you might run into a need for .equals() further down the line. We did, and since all of our VOs inherit from one VO base object, we just implement .equals() in these as necessary. It seems rather horrifying that there's no .equals() at first, but you don't really need it that often... -- Maciek Sakrejda Truviso, Inc. http://www.truviso.com -Original Message- From: frank_sommers [EMAIL PROTECTED] Reply-To: flexcoders@yahoogroups.com To: flexcoders@yahoogroups.com Subject: [flexcoders] Java-like equals() method? Date: Sat, 11 Oct 2008 02:54:18 - Hi, I've been searching for a good solution to implementing object equality. I'm familiar with ObjectUtil, etc., but it still makes things harder than they should be. It may be best to illustrate this with an example. Suppose I have a ComboBox with an ArrayCollection as a data provider. The ArrayCollection is populated with value objects from the server, e.g., User objects. Suppose that I have a Task class, and a Task may have an assignedToUser property, which is a User instance. When the someone selects a Task (say, in a master-detail view), I would like the ComboBox to set its selectedItem to the user for the given Task, i.e., combBox.selectedItem = myUser.assignedToUser. The problem is that no Task in the ComboBox's data provider and the User's assignedToUser property are ever equal using the == or === operators. So I would like to implement a custom equality for User, and have the ComboBox use that to set its selectedItem to the specified user. In Java, this is easily done by overriding the equals() and hashCode() methods of User. Any suggestions on how to achieve something similar in Flex would be much appreciated. Thanks, -- Frank
[flexcoders] Java-like equals() method?
Hi, I've been searching for a good solution to implementing object equality. I'm familiar with ObjectUtil, etc., but it still makes things harder than they should be. It may be best to illustrate this with an example. Suppose I have a ComboBox with an ArrayCollection as a data provider. The ArrayCollection is populated with value objects from the server, e.g., User objects. Suppose that I have a Task class, and a Task may have an assignedToUser property, which is a User instance. When the someone selects a Task (say, in a master-detail view), I would like the ComboBox to set its selectedItem to the user for the given Task, i.e., combBox.selectedItem = myUser.assignedToUser. The problem is that no Task in the ComboBox's data provider and the User's assignedToUser property are ever equal using the == or === operators. So I would like to implement a custom equality for User, and have the ComboBox use that to set its selectedItem to the specified user. In Java, this is easily done by overriding the equals() and hashCode() methods of User. Any suggestions on how to achieve something similar in Flex would be much appreciated. Thanks, -- Frank
[flexcoders] Re: Obtaining name of method
Thanks. I wonder how the describeType() function does its work... that seems to have access to some reflective information about a class. Actually, I have a system that uses BlazeDS for remote calls. What I'd like to do is to be able to automatically proxy server-side classes: given a method name on the local proxy, I want to be able automatically dispatch a remote method with the same name and same arguments to the server. The calls are made asynchronously and dispatch events when they return. Right now I have to refer to the current method name with a String. That's duplicate information, and also doesn't enforce that the local and remote method names are the same. I'd hate to use code generation for this, so if a Function.name property existed, that'd do the trick. Thanks, -- Frank --- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote: I bet you are trying to find a nifty way to log your code's processing, right? This comes up a lot and really, there is no good way to do it. You might try the archives, in case I missed something, but if I'd ever heard a good solution I would have used it myself. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of frank_sommers Sent: Thursday, September 25, 2008 12:39 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Obtaining name of method Hi, I'm looking for a way to obtain the name of method, given a Function object. For instance, inside a method, I can obtain a reference to the method by calling arguments.callee. But how do I then obtain from the Function object the function's name: public function testFunction():void { var f:Function = arguments.callee; // How do I get f's name (e.g., testFunction) here? } I was thinking of iterating through the object's properties, and finding if a given property is the function itself, but this only works for methods dynamically added to the object: public function testFunction():void { var f:Function = arguments.callee; for (var p:String in this) { if (f == this[p]) { // Function name is p } } } Again, this doesn't work. Any suggestions would be appreciated. Thanks, -- Frank
[flexcoders] Obtaining name of method
Hi, I'm looking for a way to obtain the name of method, given a Function object. For instance, inside a method, I can obtain a reference to the method by calling arguments.callee. But how do I then obtain from the Function object the function's name: public function testFunction():void { var f:Function = arguments.callee; // How do I get f's name (e.g., testFunction) here? } I was thinking of iterating through the object's properties, and finding if a given property is the function itself, but this only works for methods dynamically added to the object: public function testFunction():void { var f:Function = arguments.callee; for (var p:String in this) { if (f == this[p]) { // Function name is p } } } Again, this doesn't work. Any suggestions would be appreciated. Thanks, -- Frank
[flexcoders] Re: Passing data to AdvancedDataGridRendererProvider
Hi Amy, Thank you so much for the excellent advice. I ended up defining a custom event. This really is a much cleaner design. Thank you again. -- Frank --- In flexcoders@yahoogroups.com, Amy [EMAIL PROTECTED] wrote: --- In flexcoders@yahoogroups.com, frank_sommers fsommers@ wrote: Hi, I'm trying to pass some custom data into the AdvancedDataGridItemRenderer. But as far as I can see, only the datafield can be passed to this component. Is there any way to specify to the class factory some other object references, too? In my case, I want the user to be able to affect the UI state from within an item renderer, and therefore I'd like to pass references to another UI component as well to the AdvancedDataGridItemRenderer. You could do something like this renderer:ClassFactory = new myRenderer(); renderer.properties{relatedComponent:yourComponent}; Then use renderer as your itemRenderer on the ADG. If you're going to do this, you should probably create an Interface so that any component you create with that interface will work with the renderer. However, I'd suggest that instead you have your itemRenderer broadcast an event (or pick up one of the events the ADG already broadcasts) and listen for that. Trying to poke a reference to one component into another component breaks encapsulation and will result in code that's more confusing to anyone coming behind you. HTH; Amy
[flexcoders] Passing data to AdvancedDataGridRendererProvider
Hi, I'm trying to pass some custom data into the AdvancedDataGridItemRenderer. But as far as I can see, only the datafield can be passed to this component. Is there any way to specify to the class factory some other object references, too? In my case, I want the user to be able to affect the UI state from within an item renderer, and therefore I'd like to pass references to another UI component as well to the AdvancedDataGridItemRenderer. Any suggestions would be appreciated. Thanks, -- Frank
[flexcoders] Re: Adding non-XML property to an XML object
--- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote: I can't see how this would be possible. XML is essentially a string. When you pass a complex object via xml, you have to serialize it into a bunch of metadata that describes the object, so the receiver can deserialize it back into an object instance. Like SOAP. What do you need to do? I'm displaying XML data in a DataGrid, and it would be very convenient to annotate the XML data with some non-XML objects. As the XML is retrieved from the network, I'd like attach some non-XML objects to some XML nodes. Then, when the user, selects a row in the DataGrid, I could use the objects associated with the appropriate XML node to handle the item selection. I know there are many work-arounds doing this, but I was just wondering if there was a handy way of simply adding properties to the XML nodes. A broader issue, I guess, is that XML is a subclass of Object, and I do not know how to call an operator on the superclass, e.g., xml.super.myProperty = p. This doesn't work, obviously. Is there a way to override the XML object's specialization of the . and [] operators? Thanks, -- Frank
[flexcoders] AIR, BlazeDS, -services compile param
Hi, I was able to successfully build a BlazeDS application where the Flex client runs in the browser. Now, I'm trying to build an application that uses AIR and accesses a BlazeDS service remotely (invokes a remote object). I would like to configure the BlazeDS application so that the endpoints are assigned dynamically, i.e., they are not hard-coded into the application at compile time. I was not able to completely figure out how to do this, so any pointers would be very much appreciated: 1. Do I still need to reference the services XML file when compiling the application? I really would prefer to configure everything in code on the client, i.e., have no static dependencies at compile time. 2. Following Christophe Coenraets' examples in the Tomcat + BlazeDS release he had posted, I tried to define a remote destination in the AIR client as follows: var channel:AMFChannel = new AMFChannel(my-amf,http://localhost:8080/messagebroker/amf;); var channelSet:ChannelSet = new ChannelSet(); channelSet.addChannel(channel); acctSvc = new RemoteObject(); acctSvc.destination = AccountSvc; acctSvc.channelSet = channelSet; One the server, I set up a remote object with the ID AccountSvc, and there is a my-amf channel configured as well. However, when I invoke a method on this remote object from the client, nothing happens - the server does not register an invocation. Am I missing something obvious here? What other configuration parameters do I need to specify for the remote object to invoke the backend Java class? Again, I'm not specified the server's services XML file to the compiler. Could that be the problem? Thanks, -- Frank
[flexcoders] Re: Flex Builder 3 beta 3 licence
Well, is there an official word on this from Adobe? We have a Flex Charting license, and I'd love to download FlexBuilder Beta 3, but we use the charting components so I can't have the watermarks show on them. It'd be great if someone from Adobe could clarify this: Can we use the existing charting license in FlexBuilder 3 beta 3 without the watermarks showing up? Thanks, -- Frank --- In flexcoders@yahoogroups.com, Josh McDonald [EMAIL PROTECTED] wrote: Put your flex 2 serials into the .properties file in sdk/frameworks and target flex2 sdk? Works for me but I'm still on beta2, so ymmv. -Josh
[flexcoders] AdvancedDataGrid groupLabelFunction and group totals
Hi, I'm using the AdvancedDataGrid in Flex 3, and would like to use the groupLabelFunction to display the total count of items in a group. groupLabelFunction must be defined by a method that consumes the data item and an AdvancedDataGridColumn as parameters. I am not able to find a way to obtain the column groups (and group totals) that the specified column belongs to. I've seen an example of this done, e.g., : http://flexpearls.blogspot.com/2007/11/customizing-group-label-fields-when.html However, the documentation doesn't seem to provide any clues on how to obtain the group totals from within the groupLabelFunction function. Thanks, in advance, for any pointers or suggestions. -- Frank
[flexcoders] Adobe Share and PDF inside Flex
Hi, I just signed up for the Adobe Share beta. The most interesting thing so far about this service is what appears to be a PDF document displayed inside a Flex component. The component allows one to page through the document, zoom, etc. I wonder if someone on this list who is also familiar with Share could shed some light on how that's done - is there a Flex component that can display PDF pages? I've been looking for something like that for a while, but haven't had much luck finding one. The only option I've seen so far was to convert the PDF pages to a set of PNG images, and then display those inside a Flex component. What I'd much prefer would be the ability to display PDF inside Flex. Thanks, -- Frank
[flexcoders] FlexBuilder 3 Beta 2 charting and license
Hi, I realize there were several messages about this before, but I'd just like to clarify: Currently, with the FlexBuilder 3 Beta 2 trial, when I try to use the AdvancedDataGrid, for instance, the running Flex application displays a watermark to the effect that it's the Flex data visualization trial. I have a FlexBuilder 2 license, but not a charting license. If I purchased a license for Flex Charting for the Flex 2 SDK, would that license key make the watermark disappear in the AdvancedDataGrid in FlexBuilder 3, also? Thanks, -- Frank
[flexcoders] PDF rendering in Flex
Hi, I'm wondering if there is a way to render PDF inside a Flex component. I'm familiar with AIR and its ability to open PDF files using the platform's Acrobat Reader plugin, but what I'm looking for is a more light-weight approach where the PDF would be rendered by Flex itself. I've also been looking at AlivePDF, the new Flex PDF library, but I didn't find a rendering component in that API. Thanks for any suggestions, -- Frank
[flexcoders] Dynamically accessing properties of an object
I'm wondering how to dynamically access the properties of an object. I've already looked into flash.utils.describeType, which does provide a list of accessors of an object. What I'd like to be able to do is iterate through that list, and obtain the value of each accessor (if the property is readable, that is). One way I was thinking of doing this was to invoke flash.utils.getDefinitionByName on the class name + the accessor name, hoping that this would return a function object that I can invoke on the target object (this is how I would do this in Java, for instance). However, this doesn't seem to work, as I'm getting an error message to the effect that the property, e..g, myclass.myProperty, is not defined. Any suggestions would be appreciated. Thanks, -- Frank
[flexcoders] Printing newbie
Hi, I'm trying to understand how printing works in Flex. First, I saw in the documentation both mx.print.FlexPrintJob and flash.print.PrintJob being used, with slightly different syntax. Which one is the preferred way to print from Flex? (I guess it must be FlexPrintJob - but what are the advantages/disadvantages of each?) I saw in the examples that use FlexPrintJob that a component that is to be printed is first added to the current application. For instance, I saw examples like this: var pj:FlexPrintJob = new FlexPrintJob(); if (pj.start()) { var box:PrintableView = new PrintableView(); box.width = pj.pageWidth; box.height = pj.pageHeight; this.addChild(box); pj.addObject(box); pj.send(); this.removeChild(box); } Adding and then removing the component from the application causes the strange effect of PrintableView (in the above example) to be added to the app for a moment. Ideally, I wouldn't want to show the print-only component at all (not add it to the visible component tree), I'd just simply want to print it. But if I don't add the component first, then it doesn't printing either. How could that be accomplished? Thanks, -- Frank
[flexcoders] filterFunction and List selection problem
I have a List with an ArrayCollection as the data provider. When I set a filter function on the collection, a strange thing happens: When clicking on a list item, the list elements re-arrange themselves in a strange way. The item selection occurs, but the selected item moves to another list position. When no filter function is set on the list, this does not occur. Any help or suggestions as why this is happening, would be appreciated. Thanks, - -Frank
[flexcoders] Re: List item selection with filterFunction
Thanks for the suggestion. In my case, I don't change the underlying data provider, though - I simply have an ArrayCollection set as the data provider for a List. When the filter function is set, the right thing happens: Only items in the list matching the filter criteria show. However, when at that point I click on a list item, the selected item sometimes jumps, so to speak, to a position above where it originally was, and other items rearrange in the list. I don't have a sort function set for the ArrayCollection, btw. I also noticed that this does not occur when the subset created with the filter function is small, i..e, 4-5 items or less. But when the subset is bigger (a dozen or more items), this occurs every time. And when the subset is very long (few dozen items), this makes the list unusable, as users cannot reliably select list items. I also verified this with a list that has no custom item renderer, btw. Yes, I'm using 2.0.1. Thanks, -- Frank --- In flexcoders@yahoogroups.com, ben.clinkinbeard [EMAIL PROTECTED] wrote: I experienced this when checking a CheckBox itemRenderer inside a DataGrid a few motnhs back. I thought I had determined that it was a change in the underlying dataProvider that caused the problem, but if you're experiencing it just selecting an entire list item that sounds different (but obviously related). I did have some trouble reproducing this bug consistently. I reported this to our support contact at Adobe but last I heard the engineers were unable to reproduce it. He suspected it might be a bug that was introduced in 2.0.1. Is that the version you're using? There is a fairly painless workaround. In my case, just before updating the item in the dataProvider, I would set the filterFunction to null, then update the value, then reassign the filterFunction. You don't need to call refresh() (I am assuming your dp is an ArrayCollection), so the list won't unsort and resort or anything like that. Sample code below: var ff:Function = myAC.filterFunction; myAC.filterFunction = null; myAC.getItemAt(someIndex).someValue = newValue; myAC.filterFunction = ff; HTH, Ben