0 Replies Latest reply on Oct 21, 2008 1:34 AM by rahimhaji

    RemoveChild

    rahimhaji Level 1
      Dear Friends,

      i have deeloped a Ticker cum Alert RSS feed. It is working fine except the alert option. What i did was i have a empty movie clips and adding all the text int it and loading the movie clip to new native winodow. when iam closing the native window i have to remove all the text at movie clip and reset my application. My code is:

      stop();
      var showalert:Boolean = true;
      var goalert:Boolean = false;
      var inc10:Number = 0;
      var serverjointdate:String = new String();
      var serverfuldate:String = new String();
      var serverday:String = new String();
      var serverdate:String = new String();
      var servermonth:String = new String();
      var serveryear:String = new String();
      var serverhour:String = new String();
      var serverminute:String = new String();
      var serversecond:String = new String();
      var xjointdate:String = new String();
      var xday:String = new String();
      var xdate:String = new String();
      var xmonth:String = new String();
      var xyear:String = new String();
      var alertyarray:Array = new Array();
      var alertinc:Number = 1;

      function update(tit,link,categ) {
      var myXML3:XML = new XML();
      var XML_URL3 =link;
      var myXMLURL3:URLRequest = new URLRequest(XML_URL3);
      var myLoader3:URLLoader = new URLLoader(myXMLURL3);
      myLoader3.addEventListener("complete", xmlLoaded3);

      function xmlLoaded3(event:Event):void {
      myXML3 = XML(myLoader3.data);
      len3 = myXML3.channel.item.length();
      for (inc10=0; inc10<len3; inc10++) {
      //trace(myXML3.channel.item[inc10].pubDate);
      //Tue, 16 Sep 2008 08:46:13 +0000
      chkdate(myXML3.channel.item[inc10].pubDate,myXML3.channel.item[inc10].title,myXML3.channe l.item[inc10].category,myXML3.channel.item[inc10].description,myXML3.channel.item[inc10].l ink);
      }
      ///-->trace("------------------------------");
      }
      }

      function chkdate(dt,tit,cat,des,lin) {
      var dateposi:Number = dt.indexOf(" ")+1;
      var monthposi:Number = dt.indexOf(" ",dateposi)+1;
      var yearposi:Number = dt.indexOf(" ",monthposi)+1;
      xday = dt.substr(0,3);
      xdate = dt.substr(dateposi,2);
      xmonth = dt.substr(monthposi,3);
      xyear = dt.substr(yearposi,4);
      xjointdate = xday+", "+xdate+" "+xmonth+" "+xyear;
      if (xjointdate == serverjointdate) {
      var alt:alerttxt = new alerttxt();
      alt.x = 10;
      if (alertinc==1) {
      alt.y = 10;
      } else {
      alt.y = alertyarray[alertinc-1];
      }
      alertyarray[alertinc] = alt.y+alt.height;
      alertinc++;

      alt.alerttit.htmlText = "<b><a href=\""+lin+"\"><\a><\b>"+tit;
      alt.alertdesc.htmlText = "<a href=\""+lin+"\"><\a>"+des;
      alerthold.addChild(alt);

      alt.addEventListener(Event.ENTER_FRAME,altenter);
      function altenter(event:Event) {
      if (showalert == true) {
      event.target.removeEventListener(Event.ENTER_FRAME,altenter);
      //alerthold.removeChildAt(0);
      alerthold.removeChild(alt);
      alertinc = 1;
      t.reset();
      t.start();
      }
      }
      /*alt.addEventListener(Event.ENTER_FRAME, altenter);
      function altenter(event:MouseEvent) {
      if(showalert == true){
      event.target.removeEventListener(Event.ENTER_FRAME,altenter);
      alerthold.removeChild(alt);
      alertinc = 1;
      t.reset();
      t.start();
      }
      }*/

      if (showalert == false) {
      trace("can move now");
      alertscr.source = alerthold;
      if (goalert == true) {
      showalertscr();
      goalert = false;
      }
      }
      }
      }
      //---------Checking Server Date - Starts------------------------------------------
      function configureListeners4(dispatcher4:IEventDispatcher):void {
      dispatcher4.addEventListener(Event.COMPLETE, completeHandler4);
      }
      function completeHandler4(event:Event):void {
      var loader4:URLLoader = URLLoader(event.target);
      var datevars:URLVariables = new URLVariables(loader4.data);
      //fuldt=Wed, 17 Sep 2008 10:23:09 +0000&dt=17&mth=Sep&yr=2008&hr=10&mts=23&sec=09
      serverfuldate =datevars.fuldt;
      serverday = datevars.day;
      serverdate = datevars.dt;
      servermonth = datevars.mth;
      serveryear = datevars.yr;
      serverhour = datevars.hr;
      serverminute = datevars.mts;
      serversecond = datevars.sec;
      serverjointdate = serverday+", "+serverdate+" "+servermonth+" "+serveryear;
      for (inc9=0; inc9<=seldblist.length-1; inc9++) {
      update(seldblist.getItemAt(inc9).label,seldblist.getItemAt(inc9).sellk+Math.random(),seld blist.getItemAt(inc9).selcat);
      trace(seldblist.getItemAt(inc9).sellk+Math.random());
      if (inc9==seldblist.length-1) {
      showalert = false;
      goalert = true;
      //-->showalertscr();
      }
      }
      }
      var t:Timer = new Timer(10);
      t.start();

      Object(root).addEventListener(Event.ENTER_FRAME,eframe);
      function eframe(event:Event) {
      if (t.currentCount>=100 && showalert==true) {
      var loader5:URLLoader = new URLLoader();
      var request5:URLRequest = new URLRequest(" http://v5.test.arabianbusiness.com/testing/time/servertimenew.php?id="+Math.random());
      try {
      loader5.load(request5);
      configureListeners4(loader5);
      } catch (error:Error) {
      trace("Unable to load requested document.");
      }
      t.reset();
      t.start();
      }
      }

      //---------Checking Server Date - Ends------------------------------------------

      var opt2:NativeWindowInitOptions = new NativeWindowInitOptions();
      opt2.transparent = true;
      opt2.systemChrome = NativeWindowSystemChrome.NONE;
      opt2.type = NativeWindowType.NORMAL;
      opt2.resizable = false;
      opt2.maximizable = false;
      opt2.minimizable = false;
      var newwindow2:NativeWindow = new NativeWindow(opt2);
      newwindow2.stage.scaleMode = StageScaleMode.NO_SCALE;

      newwindow2.title = "Alert Window";
      newwindow2.width = 700;
      newwindow2.height = 500;
      newwindow2.x = newwidth - (newwindow2.width + 10);
      newwindow2.y = bottomlimit - (newwindow2.height + 10);
      newwindow2.alwaysInFront = true;

      function showalertscr() {
      /*var opt2:NativeWindowInitOptions = new NativeWindowInitOptions();
      opt2.transparent = true;
      opt2.systemChrome = NativeWindowSystemChrome.NONE;
      opt2.type = NativeWindowType.NORMAL;
      opt2.resizable = false;
      opt2.maximizable = false;
      opt2.minimizable = false;
      var newwindow2:NativeWindow = new NativeWindow(opt2);
      newwindow2.stage.scaleMode = StageScaleMode.NO_SCALE;

      newwindow2.title = "Alert Window";
      newwindow2.width = 700;
      newwindow2.height = 500;
      newwindow2.x = newwidth - (newwindow2.width + 10);
      newwindow2.y = bottomlimit - (newwindow2.height + 10);
      newwindow2.alwaysInFront = true;*/
      newwindow2.activate();

      var setbg2 = new altbg();
      setbg2.x = 0;
      setbg2.y = 0;
      newwindow2.stage.addChild(setbg2);
      //-------adding drag bar for dragging - starts ------------------
      var setdrg2 = new altdrg();
      setdrg2.x = 0;
      setdrg2.y = 0;
      newwindow2.stage.addChild(setdrg2);

      setdrg2.addEventListener(MouseEvent.MOUSE_DOWN,setdrgclick2);
      function setdrgclick2(event:MouseEvent) {
      newwindow2.startMove();
      }
      //-------adding drag bar for dragging - ends ------------------
      //-------adding close button in setting screen - starts ---------
      var setclose2 = new setc();
      setclose2.x = 370;
      setclose2.y = 5;
      newwindow2.stage.addChild(setclose2);
      setclose2.addEventListener(MouseEvent.CLICK, setcloseclick2);
      function setcloseclick2(event:MouseEvent) {
      alertscr.source ="";
      newwindow2.stage.removeChild(alertscr);
      //newwindow2.close();
      newwindow2.visible = false;
      showalert = true;
      goalert = false;
      }
      //-------adding close button in setting screen - ends ---------
      newwindow2.stage.addChild(alertscr);
      alertscr.x = 10;
      alertscr.y = 50;
      }

      it is giving the following error:

      ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
      at flash.display::DisplayObjectContainer/removeChild()
      at ABTickerNewCheck_fla:MainTimeline/chkdate/ABTickerNewCheck_fla:altenter()[ABTickerNewChec k_fla.MainTimeline::frame10:278]

      pls help me. i got struct up. if i finish this option i can finish my full project....

      Thanks in ADvance,

      RahimHaji