Load image in a movieclip inside two movieclips

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sumaiya
    New Member
    • Apr 2007
    • 43

    Load image in a movieclip inside two movieclips

    I know how to load dynamic images in a movieclip
    sPhoto.loadMovi e('http://localhost/1.jpg');

    I have two movieclips "mcMain" and "mcArticle"

    mcMain ---- mcArticle --- mcPhoto

    mcPhoto is inside mcArticle and is suppose load an image dynamicaly I am using the above code but it does not work. Please Help. My code is given below

    onClipEvent(loa d) {
    // create Text format properties
    var myFormat:TextFo rmat = new TextFormat();
    myFormat.font = "Verdana";
    myFormat.size = 11;
    myFormat.color = 0xffffff;
    myFormat.align = "Justify";

    var myFormat1:TextF ormat = new TextFormat();
    myFormat1.font = "Verdana";
    myFormat1.size = 11;
    myFormat1.color = 0xD5D028;
    myFormat1.align = "Left";
    myFormat1.bold = true;

    myXML = new XML();
    myXML.ignoreWhi te = true;
    myXML.onLoad = function(succes s) {
    if (success) {
    // extract XML Data
    // myRecords will be an array XML records
    myRecords = myXML.firstChil d.childNodes;

    // Get Number of Records
    totalRecords = myRecords.lengt h;
    createEmptyMovi eClip("mcMain", 0); mcMain._x = -30;
    mcMain._y = -10;


    // loop thru each record
    for (ctr = 0; ctr < totalRecords; ctr++) {

    // get data from array element
    var articleID = myRecords[ctr].attributes.id;
    var articleTitle = myRecords[ctr].attributes.myt itle;
    var articlePhoto = myRecords[ctr].attributes.pho to;
    var articleText = myRecords[ctr].firstChild;


    currentArticle = mcMain.createEm ptyMovieClip("m cArticle"+ctr, ctr);
    currentArticle. articleID=artic leID;
    if (ctr > 0) {
    currentArticle. _y = mcMain["mcArticle"+(ct r-1)]._height + 10 + mcMain["mcArticle"+(ct r-1)]._y;
    }


    // create movieclip for Article photo
    currentPhoto = mcArticle.creat eEmptyMovieClip ("mcPhoto"+c tr, ctr);
    if (ctr > 0) {
    currentPhoto._y = mcArticle["mcPhoto"+( ctr-1)]._height + 10 + mcArticle["mcPhoto"+( ctr-1)]._y;
    }
    currentPhoto.lo adMovie('http://localhost/work/photo/achieve1.jpg');




    }
    } else {
    trace ("Problem loading XML");
    }
    }
    myXML.load("htt p://localhost/work/achieve.php?d=" + new Date().getTime( ));

    //The most important function so far
    function rebuildHTML(the Text:String):St ring {
    var tempText:String = theText;
    var chunks:Array = new Array();

    chunks = tempText.split( "&lt;")
    tempText = chunks.join("<" );
    chunks = tempText.split( "&gt;");
    tempText = chunks.join(">" );
    chunks = tempText.split( "&amp;");
    tempText = chunks.join("&" );

    chunks = tempText.split( "href=&quot ;");
    tempText = chunks.join("hr ef=\"");
    chunks = tempText.split( "&quot;>");
    tempText = chunks.join("\" >");
    return tempText;
    }
    }
  • xNephilimx
    Recognized Expert New Member
    • Jun 2007
    • 213

    #2
    Hi sumaiya!
    Where are you putting that code? It is best to put the code in a frame in the main timeline, not in a movieclip. Also in there declare a variable to point to your root, like this:

    var home:MovieClip = this;

    then load the xml as you did, (but, as you are in the main timeline, don't put the onClipEvent stuff), and inside it's onLoad function you can access the movieclip that you'll load the photo into as follows:

    home.mcMain.mcA rticle.mcPhoto

    it's really easy, and putting all the code in the main timeline you ensure all the code is there and not lost in several movieclips, making all far more tidy.

    If you are creating the three movieclips dynamically you still can do this:

    [CODE=actionscri pt]
    //All of this is inside the onLoad function of the XML:
    //create the mcMain
    var main:MovieClip = home.createEmpt yMovieClip("mcM ain", 0);
    main._y = -10; //you see that you can use the reference variable main to access the newly created movieclip.

    //create the mcArticle, this is inside your "for":
    var article:MovieCl ip = main.createEmpt yMovieClip("mcA rticle"+ctr,ctr );
    //as you can see you can use the reference as the movieclip itself,
    //so main.createEmpy MovieClip is the same as
    //home.mcMain.cre ateEmptyMovieCl ip

    //I think you can get the idea from here on.

    [/CODE]

    Best regards,
    The_Nephilim

    Comment

    • shaqa
      New Member
      • Oct 2007
      • 2

      #3
      How to load imageslide when i load Contact page ore any choosen page,
      not to be loaded in the begin,
      How to load after i press button and go to choosed page and than star imageslide.?

      Comment

      Working...