Solved

Change textarea text from native window

Posted on 2009-04-10
2
629 Views
Last Modified: 2013-11-11
Hello,
I have again problem with native windows.

What i want to do is to open FIRST native window and then from that window open SECOND window. In that Second window i have function which should change text in FIRST windows text area but I always get error when i try that.

So my question is:  How to access controls in one nativ window from another window

P.S.
I know how to access controls and objects in main window::
Application.application.my_Control.text = "test".  


 
0
Comment
Question by:Didica
2 Comments
 

Author Comment

by:Didica
ID: 24119539
Ok, i will try to simplify my question with this, and hope that someone will help me:

MAIN WINDOW -----opens-----> Window 1 ------opens -----> Window2

Then

Window2 ----sends value of text box ----> Window 1
0
 
LVL 5

Accepted Solution

by:
Fuzzy_Logic_ earned 125 total points
ID: 24124093
Is this what you are after? Its a bit rough, but hopefully points you in the right direction.

Regards FL
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="600">
 
<mx:Script>
    <![CDATA[
        import mx.controls.TextInput;
        import mx.controls.Button;
        import mx.controls.TextArea;
        import mx.containers.TitleWindow;
        import flash.utils.getQualifiedClassName;
        //need button to open new TitleWindow
        
        // function to open first Window
        public function openWin1():void
        {
            
            // set up TitleWindow 1 (newWin)
            var newWin1:TitleWindow = new TitleWindow;
            newWin1.title = "Window 1";
            newWin1.name = "newWin1"; // set name to find it later
            newWin1.width = 300;
            newWin1.height = 300;
            newWin1.x = 100;
            newWin1.y = 100;
            
            // set up TextArea
            var newTextArea:TextArea = new TextArea;
            newTextArea.name = "newTextArea"; //set name to find it later
            newTextArea.width = 100;
            newTextArea.height = 100;
            newTextArea.x = 0;
            newTextArea.y = 50;
            
            // set up Button
            var newButton:Button = new Button;
            newButton.label = "Open Window 2"
            // add event listener to this button
            newButton.addEventListener(MouseEvent.CLICK, openWin2);
            
            // add controls to TitleWindow 1 (newWin)
            newWin1.addChild(newButton)
            newWin1.addChild(newTextArea);
            
            //add this window to main Application Window
            this.addChild(newWin1);
            
        }
        
        // function to open another window
        private function openWin2(me:MouseEvent):void
        {
            
            // check if window opened already
            if ( this.getChildByName("newWin2") == null )
            {
            // set up TitleWindow 2 (newWin)
            var newWin2:TitleWindow = new TitleWindow;
            newWin2.title = "Window 2";
            newWin2.name = "newWin2";
            newWin2.width = 300;
            newWin2.height = 300;
            
            newWin2.x = 300;
            newWin2.y = 200;
            
            // set up input box
            var input:TextInput = new TextInput;
            input.width = 100;
            input.height = 25;
            //add even listener for input box
            input.addEventListener(TextEvent.TEXT_INPUT, textChanged);
            
            // add input box to this window
            newWin2.addChild(input);
            
            //add this window to main Application Window
            this.addChild(newWin2);
            }
            
        }
        
        // function to close windows
        private function closeWins():void
        {
            
            // loop children and close if of type TitleWindow
            var tw:DisplayObject;
            for each ( tw in this.getChildren() )
            {
                if ( getQualifiedClassName(tw) == "mx.containers::TitleWindow" )
                {
                    
                    this.removeChild(tw);
                }
            }
            
        }
        
        // function to enter text into text area in other TitleWindow
        private function textChanged(te:TextEvent):void
        {
            // find the controls
            var titleWin:TitleWindow = this.getChildByName("newWin1") as TitleWindow;
            var textArea:TextArea = titleWin.getChildByName("newTextArea") as TextArea;
            
            // append text
            textArea.text += te.text;        
        }
        
    ]]>
</mx:Script>
    <mx:Panel title="Main Application">
        
        <mx:Button label="Open New Window" click="openWin1()">
            
        </mx:Button>
        <mx:Button label="Close Windows" click="closeWins()">
            
        </mx:Button>
        
    </mx:Panel>
</mx:Application>

Open in new window

0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I convert a CS4 FLA file to CS6? 1 873
Does Flash have a Firefox problem? 5 315
black magic design 1 129
Create animated movies for web page 18 48
This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question