Skip navigation
Currently Being Moderated

How to set Source of s:BitmapFill dinamicaly? (CODE INSIDE)

Apr 12, 2010 6:25 AM

In Flash Builder (flex 4) I try to use next code to set selected by user (from file system) Image as a repeated background. It worked with mx:Image but I want to use cool repited capabiletis of s:BitmapFill.

 

BTW: Technic I use also does not work with S:BitmapImage. Also FP does not return any errors. What Shall I do with my code to make it work?

 

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"                                     xmlns:net="flash.net.*">
 
  <fx:Script>
      <![CDATA[
        import mx.controls.Alert;
        import mx.utils.ObjectUtil;
       
        private  function btn_click(evt:MouseEvent):void  {
           var arr:Array = [];
            arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));
            fileReference.browse(arr);
        }
       
        private  function fileReference_select(evt:Event):void  {
            fileReference.load();

        }
       
       
        private  function fileReference_complete(evt:Event):void {
            img.source = fileReference.data;
            Alert.show(ObjectUtil.toString(fileReference));

           }
       
      ]]>
  </fx:Script>
 
  <fx:Declarations>
     <net:FileReference id="fileReference"
                     select="fileReference_select(event);"
                     complete="fileReference_complete(event);" />
  </fx:Declarations>
  <s:Rect id="backgroundRect" left="0" right="0" top="0" bottom="0">
     <s:fill>
        <s:BitmapFill id="img" source ="@Embed('1.jpg')" fillMode="repeat" />
     </s:fill>
  </s:Rect>
        <mx:Button id="btn"
                  label="Browse and preview..."
                  click="btn_click(event);" />
 
</s:Application>

 

Any ideas?

 
Replies
  • Currently Being Moderated
    Apr 12, 2010 7:51 AM   in reply to 7546445

    Hi,

     

    Glad you found the answer

     

    I had just redone your original posted code, same thing but changed the rect/fill to a straight bitmapimage.

     

     

    David.

     

    <?xml version="1.0" encoding="utf-8"?>

    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

       xmlns:s="library://ns.adobe.com/flex/spark"

       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

       xmlns:net="flash.net.*">

     

    <fx:Script>

    <![CDATA[

    import mx.controls.Alert;

    import mx.controls.Image;

    import mx.utils.ObjectUtil;

     

    private var ldr:Loader = new Loader();

     

    private  function btn_click(evt:MouseEvent):void  {

    var arr:Array = [];

    arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));

    fileReference.browse(arr);

    }

     

    private  function fileReference_select(evt:Event):void  {

    fileReference.load();

    }

     

    private  function fileReference_complete(evt:Event):void {

    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);

    ldr.loadBytes(fileReference.data);

    Alert.show(ObjectUtil.toString(fileReference));

    }

     

    private function onComplete(event:Event):void

    {

    ldr.contentLoaderInfo.removeEventListener( Event.COMPLETE, onComplete );

    img.source = ldr.content;

    }

     

    ]]>

    </fx:Script>

     

    <fx:Declarations>

    <net:FileReference id="fileReference"

       select="fileReference_select(event);"

       complete="fileReference_complete(event);" />

    </fx:Declarations>

    <s:BitmapImage id="img" left="0" right="0" top="0" bottom="0" source ="@Embed('myimage.jpg')" fillMode="repeat"/>

     

    <mx:Button id="btn"

       label="Browse and preview..."

       click="btn_click(event);" />

    <mx:Image id="newimg" x="430" y="227" width="515" height="392"/>

     

    </s:Application>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points