7 Replies Latest reply on Oct 19, 2009 7:18 AM by kglad

    Masking Issue

    Sreelash Level 1

      Hi,

       

                I am trying to load a colour image and then it is changed to black and white image. Here I am using a mask. But it is not getting worked. The code that i am using for this purpose is attached following:

       

      import flash.filters.ColorMatrixFilter;
      System.security.allowDomain("http://www.helpexamples.com");

       

      var flag:Boolean = true;
      var img_mc:MovieClip = _root.createEmptyMovieClip("img_mc", 100);
      var img_mc1:MovieClip = _root.createEmptyMovieClip("img_mc1", 200);
      var maskMC:MovieClip = _root.createEmptyMovieClip("maskMC", 300);
      maskMC.attachMovie("maskMC","maskMC",0);
      img_mc1.setMask(maskMC);

       


      var mcl_obj:Object = new Object();
      mcl_obj.onLoadInit = function(target_mc:MovieClip):Void {
          if(flag == true){       
              var myElements_array:Array = [0.3, 0.59, 0.11, 0, 0,
                      0.3, 0.59, 0.11, 0, 0,
                      0.3, 0.59, 0.11, 0, 0,
                      0, 0, 0, 1, 0];
              var myColorMatrix_filter:ColorMatrixFilter = new ColorMatrixFilter(myElements_array);
              target_mc.filters = [myColorMatrix_filter];
              flag = false;
          }
      }
      var img_mcl:MovieClipLoader = new MovieClipLoader();
      img_mcl.addListener(mcl_obj);
      img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc);
      img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc1);

       

      Can anybody help to solve it out.

       

      Thanks and Regards,

                        Sreelash

        • 1. Re: Masking Issue
          TarunaR

          I am not sure what you are looking for? Where you want to make the mask appear?

          • 2. Re: Masking Issue
            Sreelash Level 1

            Hi taruna,

                      Actually I am loading an image, then i change that image in to black and white image. Then again I load the same image, in which no changes are making. What I want to do is that, i need to show, half protion of image as colour and the other half as black and white. After loading the two images, I am trying to mask the half portion of colour image. Hope you understood.

             

            Thanks and Regards,

                                 Sreelash

            • 3. Re: Masking Issue
              kglad Adobe Community Professional & MVP

              this:

               

              var maskMC:MovieClip = _root.createEmptyMovieClip("maskMC", 300);
              maskMC.attachMovie("maskMC","maskMC",0);

               

              is problematic.  in addition to be poor coding, that will fail unless you have a library movieclip that has linkage id = "maskMC"?

               

              do you know what a linkage id is?

              • 4. Re: Masking Issue
                Sreelash Level 1

                LinkageID is the ID that we are giving when a movieclip is created in order to expert to flash player. Am i right? So what shold i do in order ti make the mask working.

                 

                Regards,

                     Sreelash

                • 5. Re: Masking Issue
                  kglad Adobe Community Professional & MVP

                  linkage id can be assigned anytime (in the authoring environment).

                   

                  right click on the movieclip that's in your library that you want to use as a mask, click linkage, tick export for actionscript and in the linkage id box type:

                  maskID and click ok.

                   

                  now, you can use:

                   

                  var maskHolderMC:MovieClip = _root.createEmptyMovieClip("maskHolderMC", 300);
                  maskHolderMC.attachMovie("maskID","maskMC",0);
                  img_mc1.setMask(maskHolderMC);

                   

                  though it's not clear there's any usefulness to using maskHolderMC instead of just using:

                   

                  this.attachMovie("maskID","maskMC",0);
                  img_mc1.setMask(maskMC);

                  • 6. Re: Masking Issue
                    Sreelash Level 1

                    Hi kglad, I have masked as u told me. But still masking is not working. I am attaching the modified code as follow:

                     

                    import flash.filters.ColorMatrixFilter;
                    System.security.allowDomain("http://www.helpexamples.com");

                     

                    var flag:Boolean = true;
                    var img_mc:MovieClip = _root.createEmptyMovieClip("img_mc", 100);
                    var col_img_mc:MovieClip = _root.createEmptyMovieClip("col_img_mc", 200);

                     

                    var maskHolderMC:MovieClip = _root.createEmptyMovieClip("maskHolderMC", 300);
                    maskHolderMC.attachMovie("maskID","maskMC",0);
                    img_mc.setMask(maskHolderMC);

                     

                    var mcl_obj:Object = new Object();
                    mcl_obj.onLoadInit = function(target_mc:MovieClip):Void {
                        if(flag == true){      
                            var myElements_array:Array = [0.3, 0.59, 0.11, 0, 0,
                                    0.3, 0.59, 0.11, 0, 0,
                                    0.3, 0.59, 0.11, 0, 0,
                                    0, 0, 0, 1, 0];
                            var myColorMatrix_filter:ColorMatrixFilter = new ColorMatrixFilter(myElements_array);
                            target_mc.filters = [myColorMatrix_filter];
                            flag = false;
                        }
                    }

                     

                    var img_mcl:MovieClipLoader = new MovieClipLoader();
                    img_mcl.addListener(mcl_obj);
                    img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc);
                    img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", col_img_mc);

                     

                    I had made change on the masking function oly as you told me. Please help me.

                     

                    Thanks and regards,

                                       Sreelash

                    • 7. Re: Masking Issue
                      kglad Adobe Community Professional & MVP

                      use:

                       


                      :

                       

                      import flash.filters.ColorMatrixFilter;
                      System.security.allowDomain("http://www.helpexamples.com");

                       

                      var flag:Boolean = true;
                      var img_mc:MovieClip = _root.createEmptyMovieClip("img_mc", 100);
                      var col_img_mc:MovieClip = _root.createEmptyMovieClip("col_img_mc", 200);

                       

                      var maskHolderMC:MovieClip = _root.createEmptyMovieClip("maskHolderMC", 300);
                      maskHolderMC.attachMovie("maskID","maskMC",0);

                       

                      var mcl_obj:Object = new Object();
                      mcl_obj.onLoadInit = function(target_mc:MovieClip):Void {
                          if(flag == true){      
                              var myElements_array:Array = [0.3, 0.59, 0.11, 0, 0,
                                      0.3, 0.59, 0.11, 0, 0,
                                      0.3, 0.59, 0.11, 0, 0,
                                      0, 0, 0, 1, 0];
                              var myColorMatrix_filter:ColorMatrixFilter = new ColorMatrixFilter(myElements_array);
                              target_mc.filters = [myColorMatrix_filter];

                      img_mc.setMask(maskHolderMC);


                              flag = false;
                          }
                      }

                       

                      var img_mcl:MovieClipLoader = new MovieClipLoader();
                      img_mcl.addListener(mcl_obj);
                      img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc);
                      img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", col_img_mc);