[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

user input string

I have an application that allows the user to upload fies to the server and store the path in a database so they can be associated with a certain record; this part works fine.  Now I want the user to be able to add a short description.  I am planning to use a popup (or similar control) to display when the user clicks the file upload button.  The user will then enter a description of 300 characters or less and the application will then pass that string to the function that uploads the file, so it can be added to an array.

Can someone give me an example of how to do this?  My current code is below.
//button that calls upload function
<mx:HBox width="100%" height="10%" horizontalAlign="center" >
					<mx:Button label="Add Attachment" click="Program.upload();"/>
					<mx:Button label="Remove" click="{Alert.show('Other code here')}"/>
				</mx:HBox>

public static function upload():void 
		{
		
		CursorManager.setBusyCursor();
         // listen for the file selected event
         // listen for the upload complete event
         fileRef.addEventListener(Event.SELECT, selectHandler);
         fileRef.addEventListener(Event.COMPLETE, completeHandler);
         fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA   , uploadCompleteHandler);
         fileRef.addEventListener(IOErrorEvent.IO_ERROR, onIOError)

         // browse for the file to upload
         // when user selects a file the select handler is called
         try 
         {
             var success:Boolean = fileRef.browse();
         }
         catch (error:Error) 
         {
             Alert.show("Unable to browse for files.");
             CursorManager.removeBusyCursor();
         }
      	}

Open in new window

0
PsychoDazey
Asked:
PsychoDazey
  • 2
  • 2
  • 2
2 Solutions
 
vindys80Commented:
Hi,

I think you need to send data from your description PopUp to your parent where you call the Pop Up. Right?

http://www.adobe.ca/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=layouts_065_50.html
http://livedocs.adobe.com/flex/3/html/help.html?content=layouts_12.html

These two links will help you to get clear idea about the two ways to pass data from and to popUp.
Lets know if you need some more help on this.
Thanks,
Vindys
0
 
sunsonmaheshCommented:
0
 
PsychoDazeyAuthor Commented:
Hi Vindys -

Yes, that is correct.  I have a button contained in an mxml file, when clicked I want it to open the popup then take the users input (must be <=300 characters) and pass that to my function, which is contained in  an .as file.  I am not really clear on the parent and how to pass the input to my function.

Thanks sunson, I will take a look.
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
sunsonmaheshCommented:
Hi
use mx.core.application.Application to access any variable inside the main mxml file....
from the popup component ,u could use this.parentApplication

--mahe
0
 
PsychoDazeyAuthor Commented:
Thanks, worked like a charm!
0
 
vindys80Commented:
Hi,

This is the sample popup code

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
      <mx:Script>
            <![CDATA[
                  import mx.managers.PopUpManager;
                  import mx.core.Application;
                  private function sendDesc():void{
                        test1.setDescText(_desc.text);
                        PopUpManager.removePopUp(this);
                  }
            ]]>
      </mx:Script>
      <mx:TextArea maxChars="300" id="_desc" height="100%" width="100%"/>
      <mx:Button label="OK" click="sendDesc()" enabled="{_desc.text.length}"/>
</mx:TitleWindow>



This is the mxml file

<mx:HBox width="100%" height="10%" horizontalAlign="center" >
            <mx:Button label="Add Attachment" click="upload();"/>
          <mx:Button label="Remove" click="{Alert.show('Other code here')}"/>
    </mx:HBox>
      <mx:Button label="Add Description" click="openPopUp()"/>


This is the action script part

      private var myB:MyBox;
      private static var _descText:String = "";
      private static var  fileRef:FileReference;
      public static function upload():void
                {
               
         CursorManager.setBusyCursor();
         // listen for the file selected event
         // listen for the upload complete event
         //fileRef.addEventListener(Event.SELECT, selectHandler);
         //fileRef.addEventListener(Event.COMPLETE, completeHandler);
         //fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA   , uploadCompleteHandler);
         //fileRef.addEventListener(IOErrorEvent.IO_ERROR, onIOError)

         // browse for the file to upload
         // when user selects a file the select handler is called
         try
         {
               Alert.show(_descText);
             var success:Boolean = fileRef.browse();
         }
         catch (error:Error)
         {
             Alert.show("Unable to browse for files.");
             CursorManager.removeBusyCursor();
         }
        }
      private function openPopUp():void{
            myB = PopUpManager.createPopUp(this,MyBox) as MyBox;
            PopUpManager.centerPopUp(myB);
      }
      public static function setDescText(value:String):void{
            _descText = value;
      }


I usually write actionscript function in mxml file itself. So it will be something like this.
<?xml version="1.0"?>
<!-- DataGrid control example. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.managers.PopUpManager;
	private var myB:MyBox;
	private static var _descText:String = "";
	private static var  fileRef:FileReference;
	public static function upload():void 
                {
                
         CursorManager.setBusyCursor();
         // listen for the file selected event
         // listen for the upload complete event
         //fileRef.addEventListener(Event.SELECT, selectHandler);
         //fileRef.addEventListener(Event.COMPLETE, completeHandler);
         //fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA   , uploadCompleteHandler);
         //fileRef.addEventListener(IOErrorEvent.IO_ERROR, onIOError)

         // browse for the file to upload
         // when user selects a file the select handler is called
         try 
         {
         	Alert.show(_descText);
             var success:Boolean = fileRef.browse();
         }
         catch (error:Error) 
         {
             Alert.show("Unable to browse for files.");
             CursorManager.removeBusyCursor();
         }
        }
	private function openPopUp():void{
		myB = PopUpManager.createPopUp(this,MyBox) as MyBox;
		PopUpManager.centerPopUp(myB);
	}
	public static function setDescText(value:String):void{
		_descText = value;
	}
	
]]>
</mx:Script>

	<mx:HBox width="100%" height="10%" horizontalAlign="center" >
		<mx:Button label="Add Attachment" click="upload();"/>
	    <mx:Button label="Remove" click="{Alert.show('Other code here')}"/>
    </mx:HBox>
	<mx:Button label="Add Description" click="openPopUp()"/>

</mx:Application>

Open in new window

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now