I'm using Monodevelop to build a GUI. I already have a bunch of widgets nested within a HBox which is contained within the MainWindow. However, now I release I need to add a VBox to position the menu bar at the top. My question is how, in MonoDevelop, can I add the VBox as the parent on the existing HBox?
Simply dragging a VBox onto the window doesn't do anything and I can't find a menu option.
You can do that by creating the HBox (and potentially also the VBox) in code, as opposed to in the graphic designer.
For example:
VBox vb = new VBox(); // Create a new VBox
vb.Visible = true; // Make sure it is visible
base.Add (vb); // Add the VBox to the base top window
base.Move (vb,0,0); // Make sure the VBox is placed at top-left of the window
HBox hb = new HBox(); // Create a new HBox
hb.Visible = true; // Make sure it is visible
vb.Add (hb); // Add the HBox to the VBox (so VBox is the parent)
If the HBox is already created in the graphic designer and you don't wish to re-create it on the fly this way, than adjust the code accordingly. For example, if your already existing HBox name is hb, do the following:
VBox vb = new VBox(); // Create a new VBox
vb.Visible = true; // Make sure it is visible
base.Add (vb); // Add the VBox to the base top window
base.Move (vb,0,0); // Make sure the VBox is placed at top-left of the window
vb.Add (hb); // Add the HBox to the VBox (so VBox is the parent)
Of course that means you will have to add all the menu items to VBox in code as well, but that is very easy, following the same rules. If you are not sure what member functions are available to you and how to use it, just create a new project, design the menu in the designer (using the VBox) and save. Now check the files under the folder gtk-gui, the file with the same name as your main code file (where the menu was placed) will have the exact code you need to re-create it in the original project
Hope that helps!
You can copy the pallet widget with all the controls, drag in a new pallet and paste them back in. I had to do this a few days ago when I decided to move the controls in a custom widget.
Or you could code it like the other answer, but I guess copy/pasting is faster.
Related
Complete AS3 noob here - I've tried Googling this, but I can't seem to find what I'm looking for (I stumbled across this, http://ub4.underblob.com/as3-naming-elements-dynamically/, but it doesn't weem to work for me).
I'm trying to dynamically add a Movieclip inside another Movieclip through an external AS3 class
Something like this:
var bullet:Bullet = new Bullet(x, y, "right");
var stageBackground:MovieClip = (stage.getChildByName("back") as MovieClip);
stageBackground.addChild(bullet);
However, while this compiles correctly, at run time, I get error #1009 - Cannot access a property or method of a null object reference.
The debug panel tells me the problem is with this line:
stageBackground.addChild(bullet);
But I can't seem to figure out what's wrong with it. I've tried recasting stageBackground as a Sprite, but that didn't change anything. I know the MovieClip back exists - when I reference it through near identical code in my document class, it works perfectly.
You are accessing stage here to find your container, which is very likely the problem.
You are probably thinking that the stage property refers to "the stage" in Adobe Flash authoring environment.
That's not true.
If you placed a MovieClip on "the stage" in the Flash IDE, it ends up on the main time line, this however, is not the thing the stage property is referencing. stage is the topmost DisplayObjectContainer in the display list. It only exists at runtime. It more or less represents the FlashPlayer window, the runtime environment that executes your .swf file.
In short: you are simply looking for your back MovieClip in the wrong place.
The property of a container that represents the main timeline is root.
Do not use root either.
As you can see, your code becomes dependent on the display list
structure of your application. You are already struggling to find the
container that you are looking for. If you change the structure, your code breaks. Even changing the name of the container (for example to something like "background") will wreak havoc.
Instead, use Events.
You are in another class and you want to fire a bullet.
So you create that bullet same as you do now:
var bullet:Bullet = new Bullet(x, y, "right");
Next, dispatch an Event to notify the rest of your code that a bullet was created and it should be placed in the appropriate container:
dispatchEvent(new BulletEvent(BulletEvent.CREATED, bullet));
(Create a custom event class BulletEvent that extends Event, with the apropriate setter and getter for a Bullet object)
Register a listener on the object of your class that creates the bullets, you will catch this event and place the bullet in the container:
var object:YourClass = new YourClass();
object.addEventListener(BulletEvent.CREATED, addBulletToContainer);
function addBulletToContainer(e:BulletEvent):void
{
// adding the bullet to the container
back.addChild(e.bullet);
}
This code would be placed in the parent of your back MovieClip.
The Flash IDE automatically creates variables behind the scenes that have the same names as the instance names. That's why the variable back is available here.
Using events here allows you to literally fire the bullet into your code with somebody else taking care of it, where it's easy to figure out the container it belongs into.
I am new to Gtk# and Monodevelop. So please forgive the basic-ness of this question. But I am trying to do something really simple - and I can't seem to do it. Not sure if it matters, but I am developing on Linux
I have a MainWindow which has a button. When I click on this button, I want a custom widget to pop-up
I created a custom widget as a separate project, compile it as a .dll and refer it in the main project
In the main project, I have defined a call-back for button click - loadCustomWidget()
However, the code below does not show the custom-widget on screen
public partial class CustomWidget : Gtk.Bin ; // in the other project
protected void loadCustomWidget() {
Console.WriteLine(" show custom widget ") ;
wg = new CustomWidget() ;
wg.Show() ;
}
The WriteLine() is printed. So I know the call-back is being called. But why isn't the widget showing on screen?
You need to put the widget into a container, for example add it to your main window.
My project is based on Adobe AIR/Actionscript Project and it's a small desktop application. I opened a popup using PopupManager Class. So here is code.
var _dataviewPopup = new dataviewPopup();
/* PopUpManager.addPopUp(_dataviewPopup , FlexGlobals.topLevelApplication as DisplayObject, true);
PopUpManager.centerPopUp(_dataviewPopup);
and I remove popup using
PopupManager.removePopUp(_dataviewPopup);
So I want to give some animation to this popup when it appears and disappears, is it possible?
Is there any library available for it?
Have a look at this tutorial to see how you can use the NativeWindow class to animate new windows.
Hope it helps
http://blog.flashdesign-store.com/?p=128
I have created a Flex project in Flash Builder 4.5.
Next I added fl.controls libraries (and then mx.controls libraries) in the project.
I am adding a screenshot so you can see the setup and the code.
However when I run/debug it, nothing appears in there. Totally white.
I've worked with fl.controls before, I used Flash CS5 to compile the ActionScript project and they worked correctly.
Is there any particular reason why it does not work in Flash Builder?
UPDATE: When I add graphics to the text input, i.e.
ti.graphics.beginFill(0xFF0000);
ti.graphics.drawRect(0, 0, 100, 30);
ti.graphics.endFill();
I do see a red rectangle shape. But still no editable text input box. I tried setting ti.editable = true but no use.
Try this:
Create a new FLA in Flash Professional. Add the TextInput component to your library. Notice that not only does the TextInput class get added to the library, but also a folder of "Component Assets" - skins and such. Flash Professional components are not just code - they are code and graphics.
If you want to use fl.controls.TextInput in Flash Builder, you can publish that FLA you just created with the "export swc" option checked. Include that swc in your Flash Builder project, and you'll be able to instantiate the TextInput in your code. If you want to add other Flash components, add them to the library in the FLA and republish the swc.
I would prefer using Flex itself, it will speed up your development. It's simple and does a lot of work for you.
If you do not want to do this you should give your text some properties like width, height, textFormat or use a css document for the text format. You could also give your text a border ( it should be a property of the TextInput ).
Do not forget to set the text format, otherwise the TextField doesn't know which font to use.
Sample for TextInput ( Bottom of Page )
http://help.adobe.com/de_DE/FlashPlatform/reference/actionscript/3/fl/controls/TextInput.html
Sample for Flex
http://help.adobe.com/de_DE/FlashPlatform/reference/actionscript/3/spark/components/RichEditableText.html
You can try this code:
private var ti:TextField = new TextField();
public function FormText(){
//adds ti possibly underneath 'this': stage.addChild(ti);
//adds ti on top of 'this':
stage.addChildAt(ti,getChildIndex(this));
// makes the TextField editable:
ti.type = TextFieldType.INPUT;
}
This should not only make sure that the TextField exists when the class is instantiated, but also puts the form in front of the class.
But this also assumes that the class has been added to the stage; so it may be better to add it like this:
private var ti:TextField = new TextField();
public function FormText(){
addEventListener(Event.ADDED_TO_STAGE, addedHnd);
}
private function addedHnd(e:Event)
{
removeEventListener(Event.ADDED_TO_STAGE, addedHnd);
//adds ti possibly underneath 'this': stage.addChild(ti);
//adds ti on top of 'this':
stage.addChildAt(ti,getChildIndex(this));
// makes the TextField editable:
ti.type = TextFieldType.INPUT;
}
Please review the TextField docs, too.
Why do you add your control to the stage? You should just add it to your form. i.e. this.addChild(ti)
I have 3 layers in the timeline, and I want to make a new layer, and then use the new layer to be my first frame (like a startpage).
How do I do that?
Flash does not support show/hide of layers. Learn about working with Movieclips. You should find a lot by just searching for it.
myStartClip.visible = true;
A "shaking screen" means you probably have compile errors.
Don't use layers or frames (aside from the first frame where you put all your code as usual of course).
It's an AS3 exercise, which means you should be working mainly in AS3 code, and not in frames and layers.
You put the "start page" in a container, which can be a Sprite or a MovieClip.
The "start page" can contain for instance a background, a textfield with some instructions and a start button.
This means that you have to create a new container for instance
var startContainer:Sprite = new Sprite();
addChild(startContainer); // and maybe position it with x and y
Then you create the things you need on your start page
var infoTf:TextField = new TextField();
infoTf.text = "some game description and how to play";
var bg:SomeBackground = new SomeBackground();
var startBtn:SomeBtn = new SomeBtn();
startBtn.addEventListener(MouseClick.CLICK, handleMClick_startGame);
And then you add these things to the container.
startContainer.addChild(bg); // add the other things too of course
Then when you press the startBtn, you use removeChild on the entire container and don't forget to remove the eventListener for the startBtn
After that you add the content for the game either directly on the stage, or to another mainContainer if you so prefer.
And in the end you use the same technique for the game over page.