1 Reply Latest reply on Sep 5, 2007 12:47 PM by ntsiii

    Trying to use a popup window as a component  in another component

    rite2rio
      Hi guys,
      I am unable to use a popup component in another component in
      Flex .
      Its not calling the popup compopnent.
      Could anyone plz hel me.
      This is my code.

      This is the parent component TitlWindow where i want to call my popup
      component.
      <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute" width="100%" height="100%"
      xmlns:util="userinterfaces.util.*" creationComplete="showWindow();"
      title="CREATE PROFILE">
      This is my script where i am writing a function to call a component
      whose name is fielupload.mxml
      <mx:Script>
      private function showWindow():void
      {
      pop =
      fileupload(PopUpManager.createPopUp(this,fileupload,true));//
      fileupload.mxml

      is called
      pop.title = "Please enter your login information.";
      pop.showCloseButton =true;
      PopUpManager.centerPopUp(pop);

      pop.addEventListener("close",removeMe);

      }
      </mx:TitleWindow>

      This is the code for fileupload.mxml
      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute" width="100%" height="100%"
      xmlns:util="userinterfaces.util.*" title="File Upload">
      <mx:Script>
      <![CDATA[

      import mx.collections.XMLListCollection;
      import flash.events.Event;
      import flash.events.IOErrorEvent;
      import flash.events.ProgressEvent;
      import mx.controls.Alert;
      import flash.net.FileFilter;
      import flash.net.FileReference;
      import flash.events.SecurityErrorEvent;
      import mx.controls.Button;
      import mx.controls.TextInput;
      import mx.controls.ProgressBar;
      import mx.core.Application;
      import flash.net.URLRequest;
      import flash.net.URLRequestMethod;
      import mx.core.UIComponent;
      import mx.managers.PopUpManager;

      public var fileFilterImage:FileFilter = new
      FileFilter("Images","*.png;*.gif;*.jpg");
      public var fileFilterDocument:FileFilter = new
      FileFilter("Documents", "*.txt;*.doc;*.pdf;*.rtf");
      public var fileFilterArchives:FileFilter = new
      FileFilter("Archives", "*.zip;*.tar;*.hqx");
      public var fileFilterAll:FileFilter = new
      FileFilter("All", "*.*");

      public var fileRef:FileReference;
      public var selectedId:String;

      public function init():void {
      fileRef = new FileReference();
      fileRef.addEventListener(Event.CANCEL,
      traceEvent);
      fileRef.addEventListener(Event.COMPLETE,
      completeEvent);
      fileRef.addEventListener(Event.SELECT,
      selectEvent);
      fileRef.addEventListener(IOErrorEvent.IO_ERROR,
      traceEvent);
      fileRef.addEventListener(Event.OPEN, traceEvent);
      fileRef.addEventListener(ProgressEvent.PROGRESS,
      onFileProgress);

      fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
      traceEvent);
      }

      public function traceEvent(event:Event):void {
      var tmp:String =
      "================================\n";
      }

      public function
      ioErrorEvent(event:IOErrorEvent):void{
      Alert.show("IOError:" + event.text);
      traceEvent(event);
      }

      public function selectEvent(event:Event):void{
      //var selectedId:String =
      selectButton(event);
      //Alert.show("i am in id" +
      Application.application.winMyProfile.selectedId);
      btnUpload.enabled = true;
      iptFile.text = fileRef.name;
      }

      public function
      selectButton(catchButton:Event):void{
      var newButton : Button = new Button;
      newButton = catchButton.currentTarget
      as Button
      selectedId = newButton.id;
      //Alert.show("i am in id" +
      selectedId);
      }

      public function
      onFileProgress(event:ProgressEvent):void {
      prgBarUpload.label = "Loaded " +
      event.bytesLoaded + " of " +
      event.bytesTotal + " bytes";

      prgBarUpload.setProgress(event.bytesLoaded, event.bytesTotal);

      }

      public function
      completeEvent(event:Event):void {
      Alert.show("File Uploaded
      Successfully");
      btnUpload.enabled = false;
      btnBrowse.enabled = true;

      }

      public function uploadFile(url:String):void {
      url = url + "?
      folder="+Application.application.winLogin.userInfo.getUsername();
      var req:URLRequest = new
      URLRequest(url);
      req.method = URLRequestMethod.POST;
      var folder:String =
      Application.application.winLogin.userInfo.getUsername();
      fileRef.upload(req, folder,true);
      }

      ]]>
      </mx:Script>
      <mx:VBox id="vbMain" width="100%" height="60">
      <mx:HBox width="100%" height="22">
      <mx:TextInput height="22" id="iptFile"
      width="100"/>
      <mx:Button id="btnBrowse" label="Browse"
      click="selectButton(event),fileRef.browse([fileFilterAll]);" />
      <mx:Button id="btnUpload" label="Upload"
      enabled="false"
      click="uploadFile('fileupload.do');" />
      <mx:Button id="btnCancel" label="Cancel"
      enabled="false"
      click="PopUpManager.removePopUp(this);"/>
      </mx:HBox>
      <mx:ProgressBar width="200"
      source="iptFileResume" height="5"
      id="prgBarUpload" mode="manual"/>
      </mx:VBox>
      </mx:TitleWindow>

      Its not even showing any error , i dont know whats the problem with
      it.
      Thanks for your help,
      Mario.