Book a Demo

Author Topic: Actionscript 3 Constructor params auto generation  (Read 4783 times)

maddec

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Actionscript 3 Constructor params auto generation
« on: May 10, 2008, 01:13:50 am »
[EA 7.1 build 829]
Hello,

I'm looking for 3 things to speed up my workflow in preparing models to be used with Actionscript 3 code generation.

In UML Class Diagram:

A:
Is it possible to tell somewhere that a constructor function should be automatically added to a class?

B:
I'd like to set that a var is part of a constructor parameter, and that this constructor takes it automatically as a parameter.
      1: create a var
      2: set somewhere that its data is given by a constructor function parameter
      3: parameter is automatically added to the constructor function

Is it possible ? How can I handle this?


C:
I'd like that each parameter in a constructor function are automatically associated with their Class vars counterpart (assuming they have the same name).

1: constructor function has a parameter myVar:
public function MyVar ( myVar:String ):void{
}

2: I'd like that the following is automatically added at code generation time (but only if it is a constructor(function with the same name as  class name) ):
public function MyVar ( myVar:String ):void{
      this.myVar=myVar;
}

Is it possible ? How can I handle this?

THE END RESULT should look like that:

package {
public class MyClass {

var myVar:String;

public function MyVar ( myVar:String ):void{
      this.myVar=myVar;
}
}

Ideally the only operation I should have set in EA is that myClass has a constructor, and that myVar receive it's data from the constructor function.

Thank you very much in advance for your help.

Best regards

Cedric M. (aka maddec)
« Last Edit: May 10, 2008, 06:48:42 pm by maddec »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Actionscript 3 Constructor params auto generat
« Reply #1 on: May 10, 2008, 06:46:31 am »
Have you got AS 3 set on the Tools | Options | Source Code Engineering | Actionscript page?

[It is a drop-down, and won't change until you click on the entry.]
No, you can't have it!

maddec

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: Actionscript 3 Constructor params auto generat
« Reply #2 on: May 10, 2008, 06:48:28 pm »
Hello,

I guess your question is related to my point A.

Off course I have.
I even tried | Tools | Options | Source Code Engineering | Object LifeTimes

Generate Constructor.

But I never have a constructor added automatically to my new class.


Best regards

Cedric M. (aka maddec)


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Actionscript 3 Constructor params auto generat
« Reply #3 on: May 11, 2008, 02:20:58 am »
Hi Cedric,

I figured you probably had done so, but this does occasionally trip people up. It was worth mentioning just in case, since failing to set the version could lead to many hours of fruitlessly trying (otherwise good) suggestions.

Beyond that I just don't know. Have you searched the forum for Actionscript and constructor? Perhaps you'll find something in other threads. While the EA Actionscript community is not as large as for some other languages, they are vocal. There have been many suggestions.

David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Actionscript 3 Constructor params auto generat
« Reply #4 on: May 14, 2008, 08:28:48 am »
A: First check if the class overrides the options.  (Ctrl+G | Advanced)  Then lookup Reset Options in the help to see how to change that.

If that doesn't help, check if you have a modified Class Body template.  If you do, copy it restore the original and compare the two.  You may have modified the template before the update that added this support for actionscript.

Finally, default constructors (with no parameters) are only added if generating the whole class not synchonizing.

You could achieve much of your other comments (for an initial generation at least) by modifying code templates.  (I'd look at adding a tagged value to the attributes you want set by a constructor, a custom template or two and listing over the attributes looking for that tagged value.)

maddec

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: Actionscript 3 Constructor params auto generat
« Reply #5 on: May 14, 2008, 06:41:16 pm »
Actionscript 3, code generation.
Quote
Finally, default constructors (with no parameters) are only added if generating the whole class not synchonizing.
Yes I understand this point.

Ok thanks to your comment I understood that;
1: advanced code generation has a per class base
2: it can be resetted for a complete package and sub children to default main options.

Following my test:
1: constructor is generated automatically if Options|Source Code Engineering | Object Lifetime | Generate Copy Constructor is ticked
2: the constructor is not displayed automatically into the class element operations list (visual information). It requires that code is generated first, then synchronised. Which is a bit confusing. I'd like, if possible, to see this in the operations list.
But I understand it can be a bit hard to manage because the option change regarding Object Lifetime (possible at any time) should also remove the constructor from the operations list automatically.
Regarding As3 code generation I think that Generate constructor should be always on (to apply best practices).

Quote
You could achieve much of your other comments (for an initial generation at least) by modifying code templates.  (I'd look at adding a tagged value to the attributes you want set by a constructor, a custom template or two and listing over the attributes looking for that tagged value.)

Ok, so I'll look further into it if I have some time, but I don't know much about the syntax used, so it can be hard to manage by myself, if somebody has written such functionnality, do not hesitate to forward it to me.
By the way, I feel that to add in the attribute dialog of a class element a check box [ ] "set by constructor next" to []Derived []Static [ ]Property []Const might be very useful. If this check box is checked, then EA when it generates the default constructor adds automatically as parameter of the constructor function this variable and even the this.myVariable=myVariable ....

Thank you for your previous detailed answer.

Best regards.

Cedric M. (aka maddec)
http://analogdesign.ch