I'm looking to make a "Generate component" button that will add a new component such as a Button to a Group. There could be any number of components added, so I don't want to use states. How can I do this?
var button:Button = new Button();
yourGroupId.addElement(button);
Related
I am having some problems getting this code to work properly. I want to change the text on a textfield inside a button. It works, but only for the upState. As soon as I hover or click the button, it changes back to the original name. Is there any way I can define it as anyState?
var doc:DisplayObjectContainer = m1.upState as DisplayObjectContainer;
var tf:TextField = doc.getChildAt(1) as TextField;
var boldText:TextFormat = new TextFormat();
boldText.bold = true;
tf.text = "Sterno Cleido Mastoid";
tf.setTextFormat(boldText);
Example:
http://www.testdummies.dk/dynamictext.fla
Your issue is that your code is only changing the text for the up state of the button. The other states remain unaffected.
You could simply copy and paste your code to do the same change for the over and down states - adding this code after your existing code would do just that:
doc = m1.overState as DisplayObjectContainer;
tf = doc.getChildAt(1) as TextField;
tf.text = "Neck";
tf.setTextFormat(boldText);
doc = m1.downState as DisplayObjectContainer;
tf = doc.getChildAt(1) as TextField;
tf.text = "Neck";
tf.setTextFormat(boldText);
This is an awkward way though to code a simple text change for a button. Creating a custom button class, or even making a movieClip work as a button would be much cleaner. Create a new question if you need help learning either of these things.
I would put the text field on its own layer on top of the button, so it always has the same text regardless of button state.
or, alternatively, you could copy and paste that code into each button state and then alter the code to reflect the current state. (the first solution is faster/easier though)
I'm making a sort of EPOS system but i'm stuck.
I know how to add stages in actionscript but i don't know how to add children to them stages.
This is how I make my states.
var state1:State = new State();
state1.name = "state1";
states.push(state1);
And this is how I make my buttons and try to add them
var prodBTN:Button = new Button();
prodBTN.id = products[i].id;
prodBTN.label = products[i].name.toString();
state1.overrides[new AddChild(prodBTN)];
It would be nice if anyone could help me.
Thanks in advance.
Greetz,
Gizzy
Haven't tried this but from your example shouldn't it be
state1.overrides.push(new AddChild(prodBTN));
I have created a JTable with 5 columns in it .I want the sixth column to have all cells as JComboBox from where an user can select his choice and the change will get appended in databasefor which i need a button on whose action i can fire the query to my database. So please please let me know how to add JComboBox and ButTon on JFrame...?? I am very new to Swings so do let me know how to get this donea detailed explanation about the same will be very thankful...!!! Thanks in advance..!!!
How to add JComboBox and JButton on a JFrame is rather trivial. Linking this question to the first part of your question with the table is something I did not manage. But for the part I did understand, you can have something like
JFrame frame = new JFrame( "TestFrame" );
JPanel contents = new JPanel( new BorderLayout() );
JComboBox comboBox = createComboBox();
contents.add( comboBox, BorderLayout.CENTER );
JButton button = createButton();
contents.add( button, BorderLayout.EASTH );
frame.add( contents );
frame.pack();
frame.setVisible( true );
The code illustrates how to add a combobox and a button. Note that I opted for the very simple BorderLayout. Other layouts are certainly possible, but it all depends on the requirements of your layout.
I'm writing a Flex application using Flash Builder 4 and I'm having a bit of trouble with an AS3 object. Essentially, it is a BorderContainer, with a few buttons and images, and programming logic that determines how these interact with eachother and a database.
What I want to be able to do is configure the layout/style of the inner components using MXML and CSS. I can configure the inherited objects, but not ones that I have defined...
For example, in my MXML. I can modify the (inherited) borderstroke variable of myContainer like so;
<IE:MyContainer>
<IE:borderStroke>
<s:LinearGradientStroke weight="10" rotation="270">
<s:GradientEntry color="0xF655E5"/>
<s:GradientEntry color="0x6600CC"/>
</s:LinearGradientStroke>
</IE:borderStroke>
</IE:MyContainer>
However, I can't edit the nextButton variable (which is of type Button) like this;
<IE:MyContainer>
<IE:nextButton width="100" height="30" left="10%" bottom="10%"/>
</IE:MyContainer>
If I try, I get the compile error "Could not resolve to a component implementation".
What do I need to do to make this work?!
Thanks in advance,
Aidan
EDIT:
Here's the main method of MyContainer (actually named InvestigativeEnvironment).
The call to defineTestInvestigativeEnvironment() is what takes care of setting up the objects and action listeners and such. What I want to do is change the layout and appearance of these visual components in MXML (nextButton, prevButton, toolbox, displayArea). I want to be able to set their height, width, background, x, y, horizontalCenter, etc like I can to a button that I add to a container via MXML.
public class InvestigativeEnvironment extends BorderContainer
{
private var toolbox:Toolbox;
private var bodySystem:BodySystem;
public var nextButton:Button;
public var prevButton:Button;
private var displayArea:Group;
private var image:Image;
private var toolDisplayArea:Group;
public function InvestigativeEnvironment()
{
super();
//create 'Next' button and event listener
nextButton = new Button();
nextButton.addEventListener(MouseEvent.CLICK, nextViewAngle);
nextButton.label = "Next";
this.addElement(nextButton);
//create 'Prev' button and event listener
prevButton = new Button();
prevButton.addEventListener(MouseEvent.CLICK, prevViewAngle);
prevButton.label = "Prev";
this.addElement(prevButton);
//define investigative environment by creating models.
defineTestInvestigativeEnvironment();
//Instantiate the Group that contains the model image and tool overlays
displayArea=new Group();
//Instantiate the image that is used to display the model
image = new Image();
image.source=bodySystem.getImage();
image.horizontalCenter=0;
image.verticalCenter=0;
displayArea.addElement(image);
//add toolOverlayContainer to the display area ABOVE the model image
toolDisplayArea = new Group();
toolDisplayArea.verticalCenter=0;
toolDisplayArea.horizontalCenter=0;
displayArea.addElement(toolDisplayArea);
this.addElement(displayArea);
//add toolbox to display
toolbox = new Toolbox(toolDisplayArea);
toolbox.replaceTools(bodySystem.getToolGroup());
this.addElement(toolbox);
}
I can't understand what is your problem with editing button in particular, sorry for that. But I have a lot of notices about your InvestigativeEnvironment which code you've attached.
First, you haven't follow Flex components livecycle (see here or here). So in your code you should add and configure children in createChildren() method.
But anyway you can't use your container to add children both with MXML and from code. If your adding custom components code will be executed first MXML (in your implementation with adding them in constructor it is so) all the MXML tags just remove all your added content (anyway result will be unpredictable). In other case it will be very hard to control instance's order.
I can suggest you to declare your nextButton etc as skin parts and perform their positioning in skin. This way these internal controls will be a part of border and you can add MXML children without any problem. And you can configure them within partAdded() method.
It turns out that I wasn't quite asking the right question. I wanted to edit the components, but specifically the layout and color type attributes of them.
What I need to do is set the id of the components, and then target them using CSS.
For my nextButton, I add the ID like this;
nextButton.id="nextButton";
Then I can lay it out in the MXML file (or external stylesheet) like this;
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace IE "InvestigativeEnvironment.*";
IE|InvestigativeEnvironment s|Button {
chromeColor: #336666;
}
#nextButton {
bottom: 100;
right: 5;
}
</fx:Style>
I have to create several vbox-es in a for each loop.
Now I want to do something like this.
formsArray["vb"+counter] = new VBox;
formsArray["vb"+counter].visible = true;
add labels etc.
I can't get this thing to work. Anybody any idea how to create dynamic variable names for my vbox-es?
Thanks
First off, to use an associative array, you need to use an Object and not an Array (perhaps you already are, then never mind).
You can achieve what you want to do the following way:
var vbox:VBox;
var formsArray:Object = new Object();
var counter:int = 0;
for each(<statement>)
{
vbox = new VBox();
formsArray[("vb" + counter.toString())] = vbox;
counter++;
}
The VBox's visible property is true by default, so no need to explicitly set it.
Answer to additional question in comments:
You don't really need to make use of dynamic references to do what you want to do. You'd be best of creating a custom component for this, extending the VBox class, by creating a new MXML class with VBox as the root tag. Something along these lines:
<mx:VBox ... >
<mx:Button ... click="btnClickHandler()"/>
<mx:Script>
<![CDATA[
// Toggles visibility of the VBox
private function btnClickHandler():void
{
visible = !visible;
}
]]>
</mx:Script>
</mx:VBox>
Then you can just instantiate as many of these custom VBox:es as you need. However, making the VBox invisible will make the contained button invisible as well, making it difficult to click it again. :) You probably want to address that. Anyways, I hope this will point you in the right direction.