Object generic casting/conversion of custom class

I know that the right way to do what I want is to use the ORM and type all my objects in the database that I have, but it's a little late for this approach.

So, I have an arrayCollection collection that is returned from ColdFusion. I have a custom class, call the MyClass. What is the best way, assuming that the properties match 1-1, to copy all the properties of the generic object in the collection arrayCollection in an instance of myClass with the same properties. I tried "MyClass" and not of chance (that would be nice. I happen to hit on a syntax to use 'foreach' so if you have an example or other suggestions, I would be happy.

At this point, I add any parameters to the MyClass constructor if there is an object passed, it copies the properties of an instance, but who feels 'dirty' in the sense of duty hardcode this mapping:

public var GUID:String;
public var frameName:String;
public var frameType:String;
public var helpTitle:String;
public var helpText:String;
public var baseMovieGUID:String;
public var notes: String;
public var hotspots: ArrayCollection collection;
public var JSONHotspots:String;
public var baseMovieURL:String;

public void MyClass(obj:Object_=_null):void {}
If (obj! = null) {}
GUID = obj. GUID;
frameName = obj.frameName
frameType = obj.frameType
helpTitle = obj.helpTitle
helpText = obj.helpText
baseMovieGUID = obj.baseMovieGUID
Notes = obj.notes
points = hot obj.hotspots
JSONHotspots = obj. JSONHotspots
baseMovieURL = obj.baseMovieURL
}
}
}

Does that help? http://forums.Adobe.com/message/2928367

Tags: Flex

Similar Questions

  • Failed to instantiate new custom class object - no trace of the stack

    Hello

    I have a little maddening problem. I created a custom class called 'Notification '. When I try to create an instance of the latter, I don't get any stack trace. Here's the class:

    package net.creative.core.util;
    
    import net.rim.device.api.system.Bitmap;
    
    /**
     * These are the notification objects that are created and stored
     * when a push notification is sent.
     * @author Heather
     *
     */
    
    public class Notification {
    
        private String title;
        private String content;
        private Bitmap image = Bitmap.getBitmapResource("appicon.png");
    
        public Notification(){
            title = "Title";
            content = "Content";
        }
    
        public Notification(String _title, String _content){
            title = _title;
            content = _content;
        }
        public Notification(String _title, String _content, Bitmap _image){
            title = _title;
            content = _content;
            image = _image;
        }
        public String getTitle(){
            return title;
        }
        public String getContent(){
            return content;
        }
        public Bitmap getImage(){
            return image;
        }
        public void setTitle(String _title){
            title = _title;
        }
        public void setContent(String _content){
            content = _content;
        }
        public void setImage(Bitmap _image){
            image = _image;
        }
    
    }
    

    I don't think it's a problem, but the screen I have tried to create an instance of in the Notification is in the com.creative.core package. I imported Notification on the screen while... Any ideas?

    Never mind.. just resolved.

  • ClassCastException in the custom class loader

    I created a custom class Leon.

    CCL ClassLoaderDemo = new ClassLoaderDemo(); assume that it works very well
    CLAS class = ccl.loadClass ('com '' ' MyObject');

    com MyObjectSuperClass o1 = (com. MyObjectSuperClass) clas.newInstance ();

    Now I want to get the object responsible for MyObjectSuperClass which is super class if MyObject. But I'm getting the following exception

    Exception in thread "main" java.lang.ClassCastException: com. Com cannot be cast to MyObject. MyObjectSuperClass

    Help, please.

    821458 wrote:
    My requirement is the class MyObject needs to be loaded by my client class loader. If you say that let the superclass (MyObjectSuperClass) be in the class path and let the class system charge charger, then usually it be a problem

    No, it's exactly what you want.

    MyObject loaded by the custom class loader, its super class loaded by the system class loader, I will be able to cast then.

    Yes, you will be able to cast to the upper class, then.

    It is not similar to the statement "MyObject loaded by the class loader and custom class system are different and we cannot throw.

    No, it isn't. your confusion is due to the fact that you don't seem to understand that you can have a class hierarchy that spans the Chargers of classes. This should be obvious because each object hierarchy extends eventually object, which is always in the system class loader. Therefore, you can always convert any instance of any class loader "Object". in the same way, you can have MyObjectClass in your chargers personalized classes and MyObjectSuperClass in the system class loader. You can instantiate an instance of MyObjectClass to aid reflection on your custom class loaders and assign it to a reference of the type MyObjectSuperClass. This is how pretty much any plugin system is implemented (the API is in the 'main' class loader and the implementation is in a nested class or custom ClassLoader).

  • SQLite, from SQLinstructions to a custom class

    I'm working on an AIR of FB app.

    I have a file with a source main.mxml in main.as file.

    My main.as file becomes very swollen with SQLinstructions. I want to switch to a custom class, but I do not know how to proceed.

    I found an example of a package on this page: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/data/SQLConnectio n.html #begin)

    on a 3rd down.

    The example above, that's exactly what I want to do, but I do not know how to adapt it for use in my file main.as beyond to import the class and instantiate. How can I assign my values in the class file? How to use the class to load up the dataProvider, etc...

    In addition, in the example above, the class extends Sprite. This sounds like it is for a Flash application. I always extend Sprite in Flex 4? I made a couple of simple events, data transmission to the main application with the Flash.Events.Event, so using Sprite causes some confusion.

    In a previous post, Amy suggested using Robotlegs. I think I need to get a handle on the use of Flex before I explore other architectures. I'm just not that sophisticated.

    Thank you

    Kristin

    OK, a small example

    a new package called utilities, then a new called class class actionscript DatabaseManager

    package utilities
    {
         import flash.data.SQLConnection;
         import flash.data.SQLResult;
         import flash.data.SQLStatement;
         import flash.filesystem.File;
    
         import mx.collections.ArrayCollection;
    
         public class DatabaseManager
         {
              private var sqlConnection:SQLConnection;
              private var stm:SQLStatement;
    
              public function DatabaseManager()
              {
    
                   //connect to database
                   sqlConnection = new SQLConnection();
                   sqlConnection.open(File.applicationStorageDirectory.resolvePath("whatever"));
    
                   //create tables if not exist
                   stm = new SQLStatement();
                   stm.sqlConnection = sqlConnection;
                   stm.text = "create your table here";
                   stm.execute();
    
                   //create more tables
                   //...
              }
    
              public function getThings():ArrayCollection
              {
                   stm = new SQLStatement();
                   stm.sqlConnection = sqlConnection;
                   stm.text = "your query";
                   //...
              }
    
              public function addStuff(stuff:Object):int
              {
                   //...
              }
         }
    }
    

    then in your main file, you need to import

    import utilities.DatabaseManager;
    

    instantiate the class, it connects and creates tables

    private var myDB:DatabaseManager = new DatabaseManager();
    

    then to use it

    var listFromDatabase:ArrayCollection = myDB.getThings();
    
    insertid = myDB.addStuff(thingToAdd);
    

    hope that gives you an idea

  • Custom class event does not reach Application?

    Hey everybody,

    It is probably a pretty easy question, but it left me speechless. I can handle the events of user interface components in the Application. I can handle the events of a custom user interface, within its own class object. But the dispatched event of a custom, object of the user interface does not seem to reach the Application. The event is expected to reach Application? Event if an object should be managed within the class of this object, how can I control my program flow?

    Thank you!

    I saw only he made in the settings where they inject an event dispatcher.  If you don't want to use a frame, you could have a singleton (vomits in the throat) and pass a UIComponent.  Now remember you this UIComponent must be fixed on the display as list

    var vbox:Group = new Group();

    vbox.dispatchEvent ("myEvent")

    still will not be heard by the rest of the application.  You would have to wait for a user interface component to add pass THEN to your singleton for use in the rest of the application.  Honestly, I didn't think too much about.

  • Custom class extends HashMap - error: "does not settings.

    Hi all! This is my first post on the forum, and I chose this card because it seems to be the most active. I'm relatively new to Java, but I'm already deep enough into the language.

    I have a custom class that is declared as follows:

    public class DBFRecord extends HashMap {}

    Methods here, but no constructor

    }

    The idea was to get a custom class of the hash table with a method of extracting more precisely typed values. My understanding is that, because I don't get a constructor for the class, it defaults to the parent constructor, that is, of course, HashMap(). Where I ran into trouble was when I tried to fix a compiler warning that complained a "unchecked put." I read somewhere that this can be corrected by specifying the data type of the card to the instantiation. So, I tried this:

    DBFRecord < String, Object > record = new DBFRecord < String, Object > ();

    and the compiler, instead of being pleased, slapped me with an error:

    "type com.svcon.jdbf.DBFRecord does not settings.

    So, just to prove the point, I tried:

    HashMap < String, Object > record = new HashMap < String, Object > ();

    and it worked perfectly (although of course it has messed up the rest of the royally program.)

    So, my question is this: how we declare a class of the child (if that's the right word) as she accepts the same parameters as the parent?
    public class DBFRecord extends HashMap {
    
    public class DBFRecord extends HashMap {
    
  • To access instances of a custom class that extend box

    Hello

    Forgive me if I couldn't find an answr my question with various searches in the forum, but I'm not an expert and I can't even find the right words for the search.

    Here's the problem:

    I created a class (called LAlgExpression) which extends the class box. Instances of the class are added in a box, and I tried to access these instances using mouse events.

    Now, I can actually access my custom class instances by using the properties target and currentTarget of the events, but unfortunately they are considered as belonging to the Object class and not to the class LAlgExpression which make it impossible to use all the methods I've defined for LAlgeExpression because the compiler tell me that I am trying to use on an object a method that is not defined for the class Object. What's funny is that when running when I try 'event.target is LAlgExpression' it returns true, but I don't know how to convince the compiler . It's as if the instance that I have on the screen is an object and a LAlgExpression, but the compiler will not let me treat as LAlgExpression, but only as an object and I don't understand why.

    is there a way to force the compiler to consider LAlgExpression, something he sees as an object?

    Thank you very much in advance for your help

    var obj:LAlgExpression = event.target as LAlgExpression;

    or

    var obj:LAlgExpression = LAlgExpression (event.target);

    then call methods on obj and it should go.

    If this post answers your question or assistance, please mark it as such.

    Greg Lafrance - Flex 2 and 3 certified ACE

    www.ChikaraDev.com

    Training Flex and Support Services

  • To access the properties of the custom class

    Hello again! Nevermind, I got display list order because it has me even more trouble :)

    I have several items stacked from the other (boxes) and you want to calculate the height of all the underlying boxes for each box. Each box is an instance of a "Kiste"-custom class that has a property "hoehe" (height). "." Usually, I can access this property from anywhere and it works fine. But in the following case, it won't. The alles.getChildAt(j-1) works fine with all other assets, but not with custom properties that I defined in my class?

    OK, get it myself... Type cast!

  • EventDispatcher on custom class

    I tried to create an event dispatcher in a custom data transfer object class. This is a simple class, and I don't know how send an event. I tried that extends the EventDispatcher class, but that doesn't seem to work either. Any help would be greatly appreciated.
    I enclose the application code and the custom class. It should work from what I've read, but I can't do the application to intercept the event.
    APPLICATION
    <? XML version = "1.0" encoding = "utf-8"? >
    "" < mx:Application xmlns:mx = ' http://www.adobe.com/2006/mxml ' creationComplete = "initThis ()" layout = "absolute" > "
    < mx:Script >
    <! [CDATA]
    Import mx.controls.Alert;

    private var _tester:TestClass = new TestClass();

    private function initThis (): void {}
    addEventListener (TestClass.TEST_ACTION, onTestHandler);
    }
    private void onTestHandler(event:Event):void {}
    Alert.Show ("send event");
    }
    []] >
    < / mx:Script >
    < mx:Button = "312" x y = '150' label = "Button" click = "{_tester.testEvents ()}" / >
    < / mx:Application >

    CLASS
    package
    {
    import flash.events.EventDispatcher;
    import flash.events.Event;

    SerializableAttribute public class TestClass extends EventDispatcher
    {
    public static const = "test" TEST_ACTION:String

    public function testEvents (): void {}
    dispatchEvent (new Event (TestClass.TEST_ACTION));
    }
    }
    }

    However, I found an alternative, although I still don't understand exactly. If I add the event listener directly to the class in the creationComplete apps (initThis()) as:

    _Tester.addEventListener (TestClass.TEST_ACTION, onTestHandler);

    The application intercepts the event, even if she isn't really enforcement, he is now? This is the class real, right? I'm confused about this.

  • Best way to insert data into instances of the custom class

    Hello.

    I have created a custom class (mySuperClass) in an .as file, defined constructor methods, properties, and the get/set. Now in the main .fla I must declare a large number of instances of this class and complete each property. The 'proper' method, I guess, would be to:

    var super1:mySuperClass = new SuperClass();
    super1.setProperty1 ( value1_1);
    super1.setProperty2 ( value1_2);
    ...
    super1.setPropertyN ( value1_N);

    ...
    var superM:mySuperClass = new SuperClass();
    superM.setProperty1 ( valueM_1);
    ...
    superM.setProperty1 ( valueM_N);

    However, with large quantities of variables and information that share the same basic characteristics, I feel always attempted to do through a cycle of dethrone. In that case, I'd probably build tables with the properties to complete.

    So I want to know is how would you guys do it? Are there other ways to do it?

    Thanks in advance.

    Well, the example is based on an object that has a datamodel and which can be any object of course. Now, assuming that the data come Let's say an xml file, I would use a function as the code to generate a collection of objects.
    Edit: so the StoreItem instances are created on the fly and saved in the collection

  • Dynamic class in custom class reference

    I created a custom class that I want to be able to dynamically insert a clip from the library. I'm in trouble because I want to access the clip as a property of the custom class object (ie: then it can be swapped for another clip from the library after instantiation, among other things). I use getDefinitionByName() but I can't use it outside my function addDiagram() (see attachment code) as the string variable that stores the name of the library item is undefined after the custom class constructor function. Any help is appreciated!

    Thank you
    -Erik

    I'm not quite following - are you saying you want to access panelDiagram in functions other than your addDiagram function? Just take your definition of the variable of your function and make a class variable, for example, put the following line above your constructor:
    private var panelDiagram: *;

    and in the second line of the addDiagram function, use:
    panelDiagram = new diagramClass();

    Sorry if this isn't your answer, if it's not that I'm fighting to understand the problem.

  • Unable to make a call to the custom class

    Hi all

    I train to call the custom since the screen as below class, but its not picking up the custom class features and gives the result, I don't know if something is not in the below class or the way I call this method.

    package com.ge.bbcalendar;

    Import net.rim.device.api.ui.Color;
    Import net.rim.device.api.ui.Graphics;
    Import net.rim.device.api.ui.component.LabelField;

    public class TestClass extends {LabelField
    Private boolean brought;
    private string text;
    style long private;

    public {TestClass (String text, long style)

    Super();
    This.Text = text;
    This.style = style;
    }

    protected void onFocus (int direction) {}
    focused = true;
    Invalidate();
    super.onFocus (branch);

    }

    protected void onUnfocus() {}
    concentrate = false;
    Invalidate();
    super.onUnfocus ();
    }

    protected void paint (Graphics graphics) {}
    graphics.setColor (Color.WHITE);
    graphics.setBackgroundColor (0x544E4F);
    If {(targeted)
    graphics.setColor (Color.BLUE);
    }
    Graphics.Clear;
    Super.Paint (Graphics);
    }
    }

    Called as of the screen

    SerializableAttribute public class NativeScreen extends form {}

    final cas15 TestClass = new TestClass("",LabelField.FOCUSABLE);
    }

    What is the problem above?

    I suspect that your problem is the LabelField don't think it has any text to display.

    You really need this, I think

    public TestLabel (String text, long style) {}
    Super (Text, FOCUSABLE);

    ...

  • Impossible object type cast 'VMware.Vim.ClusterVmHostRuleInf o' type 'VMware.Vim.ClusterAntiAffinityRuleSpec '.

    Hello

    I was surprised by this error. Any who see it this way? I was doing some affinity for the cluster rules. At the beginning when there was no vmgroups, hostgroups, no virtual machine to the rules of the host, this command worked very well, that no errors were generated. According to the rules of antiaffinity of vm-virtual machine, I did a few groups of MV, the host groups and created AA rules for this cluster as well via the api.  Everything has not worked well, no errors when creating. But after a few days, I wanted to add 1 more AA machine vm-virtual rule. And I received this error, no idea why this would come to the top? This error appears, but the rule is created anyway.

    PowerCLI C:\ > XYZ New-DrsRule-Cluster - name AA-vm1-vm2 - KeepTogether: $false VM - vm1, vm2
    New-DrsRule: 14/05/2012 09:30:23 impossible object type cast New-DrsRule ' VMware.Vim.ClusterVmHostRuleInf
    o ' to type 'VMware.Vim.ClusterAntiAffinityRuleSpec '.
    Online: 1 character: 12
    + New-DrsRule < < < < - XYZ - name AA-vm1-vm2 Cluster - KeepTogether: $false VM - vm1, vm2
    + CategoryInfo: NotSpecified: (:)) [new DrsRule], ViError)
    + FullyQualifiedErrorId: Client20_ClientSideTaskImpl_ThreadProc_UnhandledException, VMware.VimAutomation.ViCore.Cm
    dlets.Commands.NewDrsRule

    Thank you

    Greg

    BTW.

    Why he would mount "VMware.Vim.ClusterVmHostRuleInfo"?

    "An object of ClusterVmHostRuleInfo identifies virtual machines and the host groups that determine the position of the virtual machine. Virtual machines and the host referenced by a rule of VM-host must be in the same cluster. »

    But it is a rule antiaffinity VM - VM, not a vm host rule.  I still have no idea why the error comes out but I used onyx to see if I have the same problem when you do it with the api:

    $spec = new-Object VMware.Vim.ClusterConfigSpecEx
    $spec.rulesSpec = new-Object VMware.Vim.ClusterRuleSpec [] (2)
    $spec.rulesSpec [0] = new-Object VMware.Vim.ClusterRuleSpec
    $spec.rulesSpec [0] .operation = 'Add '.
    $spec.rulesSpec [0] = new-Object VMware.Vim.ClusterAffinityRuleSpec .info
    $spec.rulesSpec [0].info.enabled = $true
    $spec.rulesSpec [0].info.name = "AA-vm1-vm2.
    $spec.rulesSpec [0].info.userCreated = $true
    $spec.rulesSpec [0].info.vm = new-Object VMware.Vim.ManagedObjectReference [] (2)
    $spec.rulesSpec [0].info.vm [0] = new-Object VMware.Vim.ManagedObjectReference
    $spec.rulesSpec [0].info.vm [0] = 'VirtualMachine' game
    $spec.rulesSpec [0].info.vm [0] .value = "vm-xxxxxxx".
    $spec.rulesSpec [0].info.vm [1] = new-Object VMware.Vim.ManagedObjectReference
    $spec.rulesSpec [0].info.vm [1] = 'VirtualMachine' game
    $spec.rulesSpec [0].info.vm [1] .value = "vm-yyyyyyy.

    _this $ = get-view-Id "ClusterComputeResource-domain-c345645464.
    _this $. ReconfigureComputeResource_Task ($spec, $true)

    It works without errors

    Hi Greg,.

    Thank you for reporting this issue. I can also confirm that it is a bug that is caused by vm-to-host rules. We already fixed for the next version.

    Kind regards

    Yasen

  • Listen to the event within the custom class

    I created a custom class that publishes on a webpage to authorize a user. How can I listen to an event within the custom class?

    It is my code in my main class.

    var customClass:CustomClass = new CustomClass();

    var testingString = customClass.authorize ("[email protected]", "password");

    the fuction "authorizes" within the customClass looks like this:

    public void authorize(user:String,_password:String):void

    {

    jSession = new URLVariables();

    j_Loader = new URLLoader();

    jSession.j_username = user;

    jSession.j_password = password;

    jSend.method = URLRequestMethod.POST;

    jSend.data = jSession

    j_Loader.load (jSend)

    }

    How can I trigger an event in my main class once the j_Loader triggers Event.COMPLETE?

    You can raise an event using the dispatchEvent() function.

    In your main class, you assign a listener to the event the CustomClass distributes when there are.

  • create a listener for a custom class?

    I have a custom class that loads a couple of XMLs. I create an instance of this class in another class and I need to know when it is done so that I can then call a function of loading in this class of parent.

    How can I do this?

    pls know me if I need to explain differently.

    Thank you!

    When you create your instance of the class:

    ///////////////////////

    classinstance.addEventListener ("xmlloadingcomplete", f);

    private void f(e:Event):void {}

    //

    }

    ////////////////////

    and in your xml, class loading, loading is complete:

    this.dispatchEvent (new Event ("xmlloadingcomplete"));

Maybe you are looking for