1 Reply Latest reply: Mar 22, 2011 8:28 AM by kglad-zqbLf4 RSS

    Please Help: How do I add image to movie clip?

    jlfitz Community Member

         Hi Everyone,

       

             I am trying to finish creating a mouse based slider and want to dynamically create movieclip boxes inside one master movieclip. This is so I can slide the master MC left and right. Also, I want to add an image to each box. I'm getting closer but need some serious expert guidance. Right now, I can't figure out how to attach the image to the boxes.

       

            All of the dynamic stuff happens in a for loop, and when each image is loaded, it fires the Event Listener to a function to attach it. But being outside that foor loop, the new function can't reference the objects. If you have some guru in you, your time is most appreciated. I am way past a deadline and in some trouble at work.

       

           Here is the code I am talking about, followed by the FLA link with all the code:

       

           var gBox:Object = new Object(); function init(e:Event = null):void {      removeEventListener(Event.ADDED_TO_STAGE, init);      container = new MovieClip();      addChild(container);      container.y = 110;      for (var i:int = 0; i < boxCount; i++)      {                      nextXPos = i*(boxWidth+boxMargin);                      trace("NXP: " + nextXPos);                      gBox["box"+i] = new Sprite()                   with(gBox["box"+i]){           container.graphics.beginFill(0xff1111);           container.graphics.drawRect(nextXPos, 0, boxWidth, boxHeight+boxMargin);           x=nextXPos;           imgLoader = new Loader();           imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, addThumbnail);                      imgLoader.load(new URLRequest("http://www.yazizle.com/files/test_img01.png"));           addEventListener(MouseEvent.CLICK, doButton);         }                    container.addChild(gBox["box"+i]);      }      stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);      container.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);      container.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler); }

       

      and here is the link tto the FLA: http://www.yazizle.com/files/mouseSlider.zip