4 Replies Latest reply on Jan 11, 2010 7:11 AM by kglad

    Doubt regarding onPress Event

    Sreelash Level 1

      Hi,

       

      I have created different buttons on different movieclip. Then i assigned onPress event on each buttons. But the function of onPress event is not triggered. The arrangement of movieclips is following. Can anybody notify the mistake that i made. It's very urgent for me. Because today is the release date. Please help me.

       

      The pieces of code that are associated with creating button is marked with red color.

       

      var mainMC:MovieClip = _root.createEmptyMovieClip("mainMC",0);
      mainMC._alpha = 0;
      var adImgMC:MovieClip = mainMC.createEmptyMovieClip("adImgMC",0);

      var offerMC:MovieClip = mainMC.createEmptyMovieClip("offerMC",1);
      var offerList:MovieClip = offerMC.createEmptyMovieClip("offerList",0);
      var scrlBarHldr:MovieClip = offerMC.createEmptyMovieClip("scrlBarHldr",1);

       

      function processXML(xml){
          var no_Attributes:Number;
          no_Infmn = xml.firstChild.childNodes.length;
          //trace(no_Infmn)
          for(i=0;i<no_Infmn;i++){
              no_Attributes = xml.firstChild.childNodes[i].childNodes.length;
              for(j=0;j<no_Attributes;j++){           
                  switch(j){
                      case 0:
                      Name = xml.firstChild.childNodes[i].childNodes[j].firstChild.toString();
                      break;
                      case 1:
                      Address = xml.firstChild.childNodes[i].childNodes[j].firstChild.toString();
                      break;
                      case 2:
                      Offer = xml.firstChild.childNodes[i].childNodes[j].firstChild.toString();
                      break;
                      case 3:
                      Url = xml.firstChild.childNodes[i].childNodes[j].firstChild.toString();
                      break;
                      case 4:
                      Image = xml.firstChild.childNodes[i].childNodes[j].firstChild.toString();
                      break;
                  }       
              }
              infmnArr.push({_Name:Name,_Address:Address,_Offer:Offer,_Url:Url,_Image:Image});
          }
          offerContainerHt = 90*no_Infmn;
          loadAdImage(adImgUrl,adImgMC,keepRatio);   
         displayOffers();
      }

      function displayOffers(){
          offerMC._x = Width;
          var listHolder:MovieClip = offerList.createEmptyMovieClip("listHolder",0);
          //for(i=0;i<no_Infmn;i++){
          for(i=no_Infmn-1;i>=0;i--){   
              var list = listHolder.createEmptyMovieClip("list"+i,i);
              var url = infmnArr[i]._Image;
              //list._y = listHolder._height;
              //list._y = yPos;
              offerListArr.push(list);
              list.attachMovie("offerBG","offerBG",0);       
              list.offerBG._width = Width - 18.1;       
              var offerContent:MovieClip = list.createEmptyMovieClip("offerContent",1)
             
              loadImage(list.offerContent,url,i);
              //createTextField(list.offerContent,i);
             
              if(i == no_Infmn-1){
                  loadScrollBar();
                  mainMC.tween(["_alpha"],100,2,"easeInOutSine",0,Scrolling);
              }
          }   
          scrolTo = offerList._y;   
          offerContHt = list.offerBG._height;
      }

      function loadImage(listMC,url,indx){
          var Listener:Object = new Object();
          Listener.onLoadInit = function(ImageMc:MovieClip):Void  {       
              var h$ = 69*100/ImageMc._height;
              var w$ = 69*100/ImageMc._width;
              if (w$<h$) {
                  ImageMc._xscale = ImageMc._yscale=w$;
              } else {
                  ImageMc._xscale = ImageMc._yscale=h$;
              }   
              //ImageMc._xscale = ImageMc._yscale=h$;
              ImageMc._x = 9;
              //trace(ImageMc._parent._parent.offerBG._height)
              ImageMc._y = (ImageMc._parent._parent.offerBG._height-ImageMc._height)/2;       
             
              createTextField(listMC,indx);
             
          }
          //Listener.onLoadComplete = function
          var imgMC:MovieClip = listMC.createEmptyMovieClip("imgMC",0);
          var ImgLoader:MovieClipLoader = new MovieClipLoader();
          ImgLoader.addListener(Listener);       
          ImgLoader.loadClip(url, imgMC);
      }

      function createTextField(listMC,indx){   
          var imgWid:Number = listMC.imgMC._width;
          var imgHt:Number = listMC.imgMC._height;
          var imgX:Number = listMC.imgMC._x;
          var bgWid:Number = listMC._parent.offerBG._width;

       

          var textMC:MovieClip = listMC.createEmptyMovieClip("textMC",1);   
          textMC._x = imgX + imgWid + 7;
          textMC._y = 7;
         
          var txtWid:Number = bgWid - (imgX + imgWid + 10);
             
          var Nam = infmnArr[indx]._Name;
          var Add = infmnArr[indx]._Address;
          var Off = infmnArr[indx]._Offer;
         
          var name_fmt:TextFormat = new TextFormat();   
          name_fmt.font = "arial";
          name_fmt.color = 0x06b8b4;
          var nameTxt:TextField = textMC.createTextField("nametxt",1,0,0,txtWid,15);
          nameTxt.embedFonts = true;
          nameTxt.selectable = false;
          nameTxt.autoSize = true;
          nameTxt.wordWrap = true;
          nameTxt.text = Nam/*"iufgyeruiophgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghahfyeruiophgkjsphgkjsdlkjghapiou fweiofhkljsdhfgkjsdlkjghahfyeruiophgkjsdlkphgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghahfyeru iophgkjsdlkphgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghahfyeruiophgkjsdlkdlkjghapioufweiofhkl jsdhfgkjsdlkjghahfyeruiophgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghahfyeruiophiufgyeruiophgk jsdlkjghapioufweiofhkljsdhfgkjsdlkjghahfyeruiophgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghahf yeruiophgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghahfyeruiophiufgyeruiophgkjsdlkjghapioufweio fhkljsdhfgkjsdlkjghahfyeruiophgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghahfyeruiophgkjsdlkjgh apioufweiofhkljsdhfgkjsdlkjghahfyeruiophgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghahf"*/
          nameTxt.setTextFormat(name_fmt);       
         
          var add_fmt:TextFormat = new TextFormat();   
          add_fmt.font = "arial";
          add_fmt.size = 9;
          add_fmt.color = 0x808080;
          var addTxt:TextField = textMC.createTextField("addTxt",2,0,nameTxt._y+nameTxt._height,txtWid,15);   
          addTxt.embedFonts = true;   
          addTxt.selectable = false;
          addTxt.autoSize = true;
          addTxt.wordWrap = true;
          addTxt.text = Add/*"ldhfgiuperuhgkljdghdiufgyeruiophgkjsdlkjghapioufweiofhkljsdhfldhfgiuperuhgkljdghdiu fgyeruiophldhfgiuperuhgkljdghdiufgyeruiophgkjsdlkjghapioufweiofhkljsdhfgkjsdlkjghapioufwei ofhkljsdhf"*/;
          addTxt.setTextFormat(add_fmt);   
         
          var off_fmt:TextFormat = new TextFormat();   
          off_fmt.font = "arial";
          off_fmt.size = 11;
          off_fmt.color = 0xc70052;
          var offTxt:TextField = textMC.createTextField("offTxt",3,0,addTxt._y+addTxt._height,txtWid,15);   
          offTxt.embedFonts = true;   
          offTxt.selectable = false;
          offTxt.autoSize = true;
          offTxt.wordWrap = true;
          offTxt.text = Off;
          offTxt.setTextFormat(off_fmt);
         
         var bookBtnMC:MovieClip = listMC.createEmptyMovieClip("bookBtnMC",2);
          //bookBtnMC.name = indx;
          bookBtnMC.attachMovie("bookingBtn","bookingBtn",0);
          btnArray.push(bookBtnMC);
          bookBtnMC._x = listMC._parent.offerBG._width - bookBtnMC._width - 11;
         
          bookBtnMC.onPress = function(){
              trace(this);
          }

          //bookBtnMC._y = textMC._y + textMC._height + 10;
          //trace(bookingButtn)
         
         
          if(textMC._height > 65){
              var maskClip:MovieClip = listMC.createEmptyMovieClip("maskClip",3);
              maskClip.attachMovie("maskMC","maskMC",0);
              maskClip.maskMC._width = textMC._width;
              maskClip.maskMC._height = 50;
              maskClip._x = textMC._x;
              maskClip._y = textMC._y;
              textMC.setMask(maskClip);
              var dwnArrMC:MovieClip = listMC.createEmptyMovieClip("dwnArrMC",4);
              dwnArrMC.attachMovie("arr","arr",0);
              dwnArrMC._x = (bgWid - dwnArrMC._width)/2;
              dwnArrMC._y = maskClip._y + maskClip._height + 5;
              bookBtnMC._y = maskClip._y + maskClip._height + 8;
              bgHeight = bookBtnMC._y+bookBtnMC._height+5.1;
              listMC._parent.offerBG._height = bgHeight;
             
          } else {
              bgHeight = 90;
              bookBtnMC._y = bgHeight - bookBtnMC._height - 5//textMC._y + textMC._height ;
              listMC._parent.offerBG._height = 90;
              //bookBtnMC._y = textMC._y + textMC._height ;
              //listMC._parent.offerBG._height = 90;
          }
         
          offerContHt = listMC._parent.offerBG._height;
          //trace(listMC._parent.offerBG._height)
          listMC._parent._y = yPos;
         
          //lstHt =  listMC._height + 10;
          bgHt = listMC._parent.offerBG._height;   
         
          //trace(bgHt)
          //htArray.push(bgHt);   
          yPos = yPos + listMC._parent.offerBG._height;
         
          if(bgHt > Height){
              adjustHeight = bgHt - Height;
              contentHeight = -(yPos - bgHt + adjustHeight);
              //trace(contentHeight)   
          } else {
              contentHeight = -(yPos - Height/*bgHt*/)
          }   
      }

       

      I have created an event as follows:


      offerList.onRollOver = function(){
                      offerList.stopTween();
                      clearInterval(autoScrlTimer);
                  }
                  offerList.onRollOut = function(){
                      duration = 0;
                      autoScrlTimer = setInterval(automaticScroll,duration);
                      ovrFlag = true
                  }

      I doubt that the onPress event is not working because of the above piece of code.
                  

       

       

      Thanks and regards,

      Sreelash