1

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.

enter image description here

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.

Salman
  • 3,761
  • 2
  • 23
  • 34
  • I recently did this in Flash Professional, and noticed that the TextInput is not seen, but if you click in the region it is supposed to be, you can edit it (means it is there but not drawn properly) – Pranav Hosangadi Dec 17 '11 at 07:56
  • That's good. In that case i could use graphics to make it visible. I got this working in Flash anyway. But even the cursor does not appear when complied with Flash Builder. – Salman Dec 17 '11 at 08:34
  • I would really consider using Flex, its better for UI's and is working with FlashBuilder. – Felix K. Dec 19 '11 at 09:51

4 Answers4

1

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

Community
  • 1
  • 1
Felix K.
  • 6,201
  • 2
  • 38
  • 71
  • Thanks, I saw the example with fl.controls (first one). However, I am not working with FLA files. I am trying to create TextInputs (and other elements) at runtime in an ActionScript project in Flash Builder. Since I am not working with FLA, the first example does not help. And since it is AS-only project, second one does not help either. It is already a large application, I got stuck in the part where I am supposed to take some input from user. – Salman Dec 19 '11 at 10:28
  • @Salman The sample does not requires the use of a FLA file. By default the TextInput is editable so the error can't be the TextInput. Do you have mouseEnabled or mouseChildren disabled in a parent of the class? If not you really should check your textFormat, it it is not set you not gonna see anything. You could simply test it by setting a text to it ( ti.text = "MyText" ). If you see a text and can't edit it i would debug the text field and see if some cracy shit happend and flash changed some properties which should not be changed. – Felix K. Dec 19 '11 at 10:35
  • Apparently some crazy shit did happen, I do not see anything even after setting the text. – Salman Dec 19 '11 at 10:57
  • So you did not set the `textFormat` property, this can't work. After setting it everything should work. – Felix K. Dec 19 '11 at 10:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5979/discussion-between-salman-and-felix-k) – Salman Dec 19 '11 at 11:02
1

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.

iND
  • 2,663
  • 1
  • 16
  • 36
  • Please see the addition my answer above. – iND Dec 21 '11 at 19:08
  • OK, it nearly works :) After editing the TextField if I `trace(ti.text)` it still shows the original value, not the edited value. Any idea how I get the edited value? I am going through flash.text documentation but yet to find a solution. – Salman Dec 22 '11 at 13:27
  • Sounds like you are not changing text at the right time. Can you post the code you are using to add text and also to copy text? – iND Dec 22 '11 at 17:43
1

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.

duggulous
  • 2,427
  • 3
  • 23
  • 40
  • Thanks, but I am working with a desktop AIR application in Flash Builder. I need a specific solutiun for the scenario. Using an FLA is not an option. Moreover, I need to create textinputs and other input elements in runtime, without using the components library. – Salman Dec 21 '11 at 10:58
  • Why is using an FLA not an option? You only need to open the fla once, in order to create the swc. You could easily download a trial version just to produce the swc. Once you have the swc in your Flash Builder project, you can create all those components at runtime. – duggulous Dec 21 '11 at 19:12
0

Why do you add your control to the stage? You should just add it to your form. i.e. this.addChild(ti)

laurent
  • 88,262
  • 77
  • 290
  • 428