Netbeans Swing: Variables declaration disappeared - swing

Got a question:
Just modified my Swing GUI a bit by resizing some buttons and recompiled...then:
cannot find symbol symbol: variable MachineStatusLabel and more of the same for other Objects...
Yep, this is a Label in my GUI, no idea why it cannot be found. The generated code section contains the usual stuff like
javax.swing.JLabel MachineStatusLabel = new javax.swing.JLabel();
and defines everything. But looking at the Variables declaration - do not modify-Section, almost all GUI Objects disappeared! There are only two left:
// Variables declaration - do not modify
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
// End of variables declaration
Is there a way to let NetBeans rebuild the whole GUI into this generated code? Somehow the GUI Objects seem to have just been messed up by NetBeans :-( Adding the declarations for the missing Objects manually didn't help either...
Thanks in advance!
Patrick

You should double check the value of the 'Generate Components as' property in the Options dialog.
The Option appears of the GUI Builder tab of the Miscellaneous category.
Here is the screenshot...
It sounds like you need to have the property value set as 'Fields in Form Class'.
If you change the option value, you will probably need to make a minor change in your form to trigger a code regeneration, too.

Related

PhpStorm autocomplete __construct method

When you write public function __ PhpStorm prompt's a list of Magic Methods
So if you, for instance, want to create a constructor for your class, you would use __construct magic method. For example, I typed __con and PhpStorm detect's my intention of creating a constructor thus a prompt window suggests me to auto-create one.
Once you hit Enter the method is created.
While this is pretty nice, I would really love to have the cursor automatically placed between parenthesis like this: public function __construct(|) (the vertical bar "|" illustrates the cursor), and that would give me the ability to write the params needed for the constructor, in case I don't need any properties, I could press Tab and the cursor would move to the body of the method like this:
public function __construct()
{
|
}
From what I read in PhpStorm documentation, I did not found anywhere to be mentioned that you can edit those suggestions by PhpStorm, so I believe that in order to archive what I'm describing I have to go with a live template like this:
So my question is: Is my approach the only way to archive that or there is a way to edit the PhpStorm build-in suggestion for the class constructor magic method?
Thanks!
This is a known problem, please vote for WI-33646.

Issue with Document Class and Tutorial

So I've been following this tutorial on AS3 and Flash. Its been going well until, note I have tried to contact the writer of the tutorial and had no reply. Here's what it tells me to do;
Right-click PlayScreen in the library, select Properties, and check Export for ActionScript. This time, instead of accepting the default value, enter the name of your document class. Click OK.
So it pops up an error, first we’ll have to make a new document class, since no two different objects can share the same class. Cancel the Properties box.
Hit File > New and select ActionScript File. Enter the (by now familiar) code.
Save this in the Classes directory as DocumentClass.as. (There’ll be no confusing the purpose of this file!) Now, back in your FLA, change the document class to DocumentClass.
Check everything’s fine by clicking that pencil icon — if it’s all OK, that should bring up the AS file that you just created.
// So this bits all fine, its the next that i'm stuck with:
Now you can set the PlayScreen‘s class to AvoiderGame. So do so!
// So I go ahead into the properties and change the name but then it pops up with the same error as before: 'Please enter a unique class name that is not associated with other library symbols'
What does this mean!? How do I resolve this!?
Full tutorial here:Flash Tutorial
Its hard to tell what you are trying to accomplish without knowing what all the parts you are referring to actually do, which are objects in the library and which are classes, but maybe this can help:
First of all, document class in AS3 typically refers to the project's main set of code that initializes the app. This class can be called anything but is often called Main, and is entered in the property panel that is displayed when you click the projects main stage in the field called class.
Now, when linking a class to an object in the library, its a little different. In the library object's property panel, tick the box for Export for Actionscript, and put a unique name in the top box. This is what you reference in your code to call it, like new somethingOrOther() or using the pic below as an exaample, new Ball(). The second box is the base class, pathed to where it lives in your code base. This is the class you will write that actually controls the object you've linked the class to. Giving a linked object a base class and a unique identifier allows you to use the same base class for multiple linked objects.
Note that when you do this approach, Flash will warn you that there is no class associated with Ball and one will be created for you. Don't worry, this is normal behavior. If you set this up properly, your object will still be controlled by its base class.

Working with OOP and TimeLine

I'm having a problem using flash CS6 (or CS*), where I want to be able to create symbols in the interface and link them to an as3 class. The problem is that when editing the class the code hints don't work correctly, i suppose because the CS* interface doesn't tell the code the object types.
For example:
I create a symbol and link it to a class (myclasses.SomeDisplayObject)
I now create and edit this class in the flash pro code editor, but the editor doesn't know any of the object properties.
To combat the problem I've been creating private properties on the class and assigning them in the construct. This way I can set the type and code hinting works. This is a real nuisance and I have in one class 50 lines of variable assignments.
There must be a better way of doing it and I'm hoping someone here knows about it.
Just turn off "declare stage instances automatically" and declare them as public properties. For more specifics on how to deal with OOP on the timeline, check out http://www.developria.com/2010/04/combining-the-timeline-with-oo.html and http://www.meetup.com/atlflex/files/
The IDE (or any other code tool you choose to use, like Flash Builder), should then recognize your instances.
You could use a different editor. For instance, there is FlashDevelop

What is the data type from the source of an image

another flashbuilder brainbreaker for me...
I have a class with a contstructor that should only change the source of an image.
[Bindable]
[Embed(source='../pictures/test.jpg')]
private var _picture:Class;
public function Test(newSource:*****)
{
_picture.source = newSource;
}
(the image is not an image, but a class, I am aware of this, it is meant to be so :-) )
The problem is that when I call the constructor, let's say:
var test:Test = new Test(pictureAtStage.source);
Flashbuilder will give an error, becouse I can't tell the compiler what data type "newSource" at the constructor will have...
*edit:
When i use _picture.source, the embedded source does not seem to be changed...?
Anyone knows an answer?
Are we talking about mx.controls.Image? if so, then the source of an image can be: a Class, a Bitmap (not a BitmapData), a String (in which case it is assumed that you wanted to load it instead of using an embedded one). If you want to find a common denominator for all these, then Object is that class, however, I would rather limit it to something particular to your use case.
However, if I may advise anything... don't use mx.controls.Image, it's too bloated, even for Flex framework. If it must be a UIComponent - extend UIComponent and let the source be of type BitmapData - this way you will be able to manage resources better - you could reuse the same actual image for example. You could then use graphics property of the control to display the image.
Another advise, if you are still here :) Don't use [Bindable], especially the short version of it, especially not on a private variable - you will save yourself the frustration of countless hours of debugging it... Besides, in your case you aren't going to change the value of that variable anyway...
Are you still here? Well, don't use [Embed] on variables, use it on class definition - slightly more work for you, but this will, potentially, make your code more portable. If you embed on class the compiler will not generate a silly "something-something-Asset" class, it will use Bitmap or BitmapData - whichever your class extends. Thus, you will not introduce a dependency on Flex framework, and, in general, you will have more control over your code.
EDIT: the above was written assuming that _picture (class) variable and _picture (some variable used in a function) are not the same thing. But if they are the same thing, then Class class is dynamic, which means that you can add to it properties at runtime (don't know why, it's a design decision by Adobe...), however, the compiler will act as if it's not possible, so you would work around that by adding the property through reflection:
var _picture:Class = Sprite;
_picture["source"] = whatever;
trace(Sprite["source"]);
This is indeed slightly confusing, It will be of the type BitmapAsset which extends Bitmap. So any of those will work.
Since I'm very new to flashbuilder I didn't see the obvious solutions...
The solution for the first part of my question (before the edit):
Setting the data type to Object did the trick:
[Bindable]
[Embed(source='../pictures/test.jpg')]
private var _picture:Class;
public function Test(newSource:Object)
{
_pucture.source = newSource;
}

Storing Multiple Images In A Variable With Action Script 3 In Flash Builder 4.5

I have a flash assignment that I need help getting started, any advice would be greatly appreciated. The assignment is to create an application for playing a card game, I have to create an MXML component that has two variables, one variable stores the image of the back of a playing card, the other variable has t store all 52 options of a front facing card (the second variable will store over 50 images).
I've written the variable for the back of the card image like this:
public var backOfCard:Image = new Image();
backofCard.source = 'asset/backImage';
However I get an undefined variable error (1120: Access of undefined propery variable img1), I feel like there's something small that I'm missing here, but I was wondering if anyone could spot it.
I'd also like to know if I should use the same method for each jpg image for the front of the cards, it seems like it would be a lot of repetitive code aside from the change in filename for the front of the card images.
Here's a snippet of the homework assignment, again I just need help getting this part correct, I really appreciate any help with this.
Your job is to supply the custom component named Card. Create the
component by using File → New → MXML Component. In the popup dialog
box
leave the Package blank
Name the component Card
Base Card on spark.components.Image
What goes into the Card component?
For each card, we'll want to be able to show the front face of the
card, or its back face. That means each card should have a place to
store information about what file to show as its front face, and what
file to show as its back face.
To do this, create two variables in the Card component to store the
file names. You might call these variables backImage and frontImage.
Your access modifier is what's bothering me.
If you're creating these definitions in your class file, then the first statement works:
public var backOfCard:Image = new Image();
But if you're in one of the methods, usually the constructor (sometimes called the ctor), or any other method of the application, you could use the 2nd statement:
backofCard.source = 'asset/backImage';
But the combination of both is what I think is confusing. Because the "access modifier" (i.e. public, private, internal, protected) is what you use to define variables and methods within a class. And since you're putting both side-by-side (a definition and an assignment statement), I think you're mixing when to declare them.