5 Replies Latest reply on Jul 8, 2011 7:03 AM by kglad

    setPixel in flash using xml....?

    smilelilac Level 1

      Hi ,

       

      I have tried this in flash i got the result but now i am trying to change the color of the bitmap using setpixel values using xml.


      First i am creating a new bitmap and then i have a button when i click on the button the pixel values or the color of the bitmap should be changed.

       

      script for creating a bitmap:

       

      import flash.display.BitmapData;
      var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00CCCCFF);
      var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
      mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

       

       

      Script on the button:

       

      on (release) {
          for (var x:Number = 0; x<50; x++) {
              for (var y:Number = 0; y<10; y++) {
                  myBitmapData.setPixel32(x, y, 0x11FF00);
              }
              for (var y:Number = 11; y<20; y++) {
                  myBitmapData.setPixel32(x, y, 0xCCFF00);
              }
              for (var y:Number = 21; y<50; y++) {
                  myBitmapData.setPixel32(x, y, 0x11FFEE);
              }
          }
      }

       

      Now i just want to change the color of the bitmap using setpixel using xml and calling the xml into flash.

        • 1. Re: setPixel in flash using xml....?
          kglad Adobe Community Professional & MVP

          use the xml class to load and parse your xml and assign variables used in your setPixel() methods:

           

          var xml:XML=new XML();

          xml.onLoad=parseXML;

          xml.load("yourxml.xml");

           

          function parseXML(){

          // parse your xml and assign variables

          }

          • 2. Re: setPixel in flash using xml....?
            smilelilac Level 1

            Hi kglad,

             

            Thanks for your quick response,I have tried the code but it is not working ..

             

            here i am writing the code please go through it...

             

            script on frame 1 :

             

            import flash.display.BitmapData;
            var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00CCCCFF);
            var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
            mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
            rb_btn.onRelease = function(success) {
            var myXML:XML = new XML();
            myXML.ignoreWhite = true;
            myXML.onLoad = parseXML;

             

            };
            myXML.load("colors.xml");

             

             

            Script in xml file:(colors.xml)

            <xml version="1.0"?>
            <colo>

            function parseXML(){
                for (var x:Number = 0; x<50; x++) {
                    for (var y:Number = 0; y<10; y++) {
                        myBitmapData.setPixel32(x, y, 0x11FF00);
                    }
                    for (var y:Number = 11; y<20; y++) {
                        myBitmapData.setPixel32(x, y, 0xCCFF00);
                    }
                    for (var y:Number = 21; y<50; y++) {
                        myBitmapData.setPixel32(x, y, 0x11FFEE);
                    }
                }

            }
            <colo/>

            • 3. Re: setPixel in flash using xml....?
              kglad Adobe Community Professional & MVP

              you can't load uncompiled executable code (like a function in xml) during runtime.  there is no workaround.

               

              you can load compiled code during runtime (like a swf) and you can load data and use that in executable code.

              • 4. Re: setPixel in flash using xml....?
                smilelilac Level 1

                Hi kglad,

                 

                Well i am confused, I am searching that how would be the attributes for setpixel in xml file?How can we assign setpixels from xml.

                 

                for example when we load a dynamic data into flash which has three dynamic texts "name_txt,count_txt,type_txt" and when we click on the button "rb_btn" xml data will be loaded into the three dynamic text fields.  So below is my code in xml and in flash.


                script in xml:

                <?xml version="1.0" encoding="utf-8"?>
                <Books>
                <Book name="Harry Potter" count="1" type="Asian"/>

                </Books>

                 

                script on first frame:
                import flash.display.BitmapData;
                var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00CCCCFF);
                var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
                mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
                var myXML:XML = new XML();
                myXML.ignoreWhite = true;
                rb_btn.onRelease = function(success) {

                        var bookName = myXML.firstChild.childNodes[0].attributes.name;
                        var bookCount = myXML.firstChild.childNodes[0].attributes.count;
                        var bookType = myXML.firstChild.childNodes[0].attributes.type;
                        name_txt.text =
                bookName;
                        count_txt.text =
                bookCount;
                        type_txt.text =
                bookType;
                        };
                myXML.load("colors.xml");

                 

                 

                So we are assigning a name in xml called "name="Harry Potter" "we are calling it flash as

                "var bookName = myXML.firstChild.childNodes[0].attributes.name;" And my question is how or what is the process to write a code for setPixel in xml and calling  it into flash.

                • 5. Re: setPixel in flash using xml....?
                  kglad Adobe Community Professional & MVP

                  in parseXML(), what parameters do you want to be loaded from the xml.  for example, you can load the colors (0x11ff00 etc) and you can load the x,y limits.  parseXML() would then use variables whose values are supplied by your xml:

                   

                  function parseXML(){
                      for (var x:Number = 0; x<xvar; x++) {
                          for (var y:Number = 0; y<yvar1; y++) {
                              myBitmapData.setPixel32(x, y,col1);
                          }
                          for (var y:Number = yvar1; y<yvar2; y++) {
                              myBitmapData.setPixel32(x, y, col2);
                          }
                          for (var y:Number = yvar2; y<yvar3; y++) {
                              myBitmapData.setPixel32(x, y, col3);
                          }
                      }

                  }