A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Help Loadvars->onData .vs MovieClip.loadClip

  1. #1
    Junior Member
    Join Date
    Jul 2004
    Posts
    19

    Help Loadvars->onData .vs MovieClip.loadClip

    Got the following AS2 code (built in CS4):
    Code:
    var ar_movies:Array = new Array();
    var ar_links:Array = new Array();
    var my_lv:LoadVars = new LoadVars();
    var movieIndex:Number = 0;
    
    my_lv.onData = function(src:String) {
      if (src == undefined) {
          trace("Error loading content.");
          return;
      }; //if (src == undefined)
      my_lv.decode(src);
      x = 0;
      for (var prop in my_lv) {
        // ****************************************
        // Here is output from the PHP script (wrapped):
        // image0=mysite.com/banners/banner1.swf&
        // image1=mysite.com/banners/banner2.swf&cant=2
        // ****************************************
        if(prop.indexOf('image') > -1) {
          ar_movies.push(my_lv[prop]);
          x++;
        }; // if(prop.indexOf('image') > -1)
      }; // for (var prop in my_lv)
      // ****************************************
      // ar_movies is now loaded
      // ****************************************
    };
    my_lv.load('www.mysite.com/banner.php', my_lv, "GET");
    
    var playedOnce:Boolean = false;
    var depthNum:Number = this.getNextHighestDepth();
    var container_mc:MovieClip = this.createEmptyMovieClip("container_mc", depthNum);
    var MCL:MovieClipLoader = new MovieClipLoader();
    var mListener:Object = new Object();
    mListener.onLoadInit = function(target_mc:MovieClip) {
      var url:Array = target_mc._url.split("/");
      var fileName:String = url[url.length-1];
      target_mc.onEnterFrame = function() {
         trace ("currentFrames:" + this._currentframe);
         trace ("totalFrames:" + this._totalframes);
        if (this._currentframe == this._totalframes) {
          delete this.onEnterFrame;
          this.stop();
          if (playedOnce == false) {
            playedOnce = true;
            // ****************************************
            // Outputs: Loading: undefined
            // ****************************************
            trace ("Loading:" + ar_movies[movieIndex]);
            MCL.loadClip(ar_movies[movieIndex], container_mc);
            // ****************************************
            // On the next line, I get a Syntax error, 
            // wondering why???
            // ****************************************
            // movieIndex++;
          } else {
            trace("All Done, "+fileName+" Complete");
          }; // if (playedOnce == false)
        }; // if (this._currentframe == this._totalframes)
      }; // target_mc.onEnterFrame = function()
    }; // mListener.onLoadInit = function(target_mc:MovieClip)
    MCL.addListener(mListener);
    
    // ****************************************
    // Outputs undefined because it hasn't been loaded yet...
    // ****************************************
    trace ("Loading:" + ar_movies[movieIndex]);
    MCL.loadClip(ar_movies[movieIndex], container_mc);
    // ****************************************
    // After loading first one, increment so second will be 
    // loaded when first one finished
    // ****************************************
    movieIndex++;
    I am able to fill the array just fine now but the clip is trying
    to load before the LoadVars is finished loading.

    Help???? (see comments in code)

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Im not really sure ..but cant you just call/load the movieClip from the onData/onLoad event in the LoadVars object?

  3. #3
    Junior Member
    Join Date
    Jul 2004
    Posts
    19
    Cool...thanks for the tip...

    OK, I've got it working where it rotates between the SWFs. But I can't
    understand why the statusbar is constantly saying
    "Reading www.listinventory.com"

    Is there a way to stop that from happening?

    Also, when I change the code in the onEnterFrame to increment movieIndex
    instead of decrement, it doe not loop more than once. Any ideas?

    PHP Code:
    var ar_movies:Array = new Array();
    var 
    ar_links:Array = new Array();
    var 
    my_lv:LoadVars = new LoadVars();
    var 
    movieIndex:Number 0;
    var 
    depthNum:Number this.getNextHighestDepth();
    var 
    container_mc:MovieClip this.createEmptyMovieClip("container_mc"depthNum);
    var 
    MCL:MovieClipLoader = new MovieClipLoader();
    var 
    mListener:Object = new Object();

    mListener.onLoadInit = function(target_mc:MovieClip) {
      var 
    playedOnce:Boolean false;
      var 
    url:Array = target_mc._url.split("/");
      var 
    fileName:String url[url.length-1];
      
    target_mc.onEnterFrame = function() {
        if (
    this._currentframe == this._totalframes) {
          
    delete this.onEnterFrame;
          
    this.stop();
          if (
    playedOnce == false) {
            
    playedOnce true;
            
    MCL.loadClip(ar_movies[movieIndex], container_mc);
            if (
    movieIndex == 0) {
              
    movieIndex ar_movies.length-1;
            } else {
              
    movieIndex--;
            } 
    // if (movieIndex == 0)
            /*
            // If I try it this way, it won't rotate back to the first movie.
            if (movieIndex == ar_movies.length) {
              movieIndex = 0;
            } else {
              movieIndex++;
            } // if (movieIndex == ar_movies.length)
            */
            
    trace(movieIndex);
          }; 
    // if (playedOnce == false)
        
    }; // if (this._currentframe == this._totalframes)
      
    }; // target_mc.onEnterFrame = function()
    }; // mListener.onLoadInit = function(target_mc:MovieClip)
    MCL.addListener(mListener);

    my_lv.onData = function(src:String) {
      
    /*
      The data is loaded in like a query string this format:
      index0=http://www.mysite.com/movie1.swf&index1=http://www.mysite.com/movie2.swf&cant=2
      
      variable cant is noo longer used.
      */
      
    if (src == undefined) {
        
    trace("Error loading content.");
        return;
      }; 
    //if (src == undefined)
      
    my_lv.decode(src);
      
    0;
      for (var 
    prop in my_lv) {
        if(
    prop.indexOf('image') > -1) {
          
    ar_movies.push(my_lv[prop]);
          
    x++;
        }; 
    // if(prop.indexOf('image') > -1)
      
    }; // for (var prop in my_lv)
      
    MCL.loadClip(ar_movies[movieIndex], container_mc);
      
    movieIndex++;
    };
    my_lv.load('http://www.listinventory.com/banner.php'my_lv"GET"); 
    Preview HTML:
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>CrimpToolsRotator</title>
    </head>
    <body bgcolor="#8080FF">
    	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 
    	        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" 
    	        width="715" height="90" 
    	        id="CrimpToolsRotator" align="middle">
    	<param name="allowScriptAccess" value="sameDomain" />
    	<param name="allowFullScreen" value="false" />
    	<param name="movie" value="CrimpToolsRotator.swf" />
    	<param name="quality" value="high" />
    	<param name="bgcolor" value="#ffffff" />	
    	<embed src="CrimpToolsRotator.swf" quality="high" bgcolor="#ffffff" width="715" 
    	       height="90" name="CrimpToolsRotator" align="middle" allowScriptAccess="sameDomain" 
    	       allowFullScreen="false" type="application/x-shockwave-flash" 
    	       pluginspage="http://www.macromedia.com/go/getflashplayer" />
    	</object>
    </body>
    </html>
    Last edited by MrBaseball34; 07-12-2010 at 11:49 PM.

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I think the status bar thing is just because its "FLASH"..

    I dont think it goes away..but who knows..LOL

    if you want you can post an AS2 version in F8 or CS3 format.. and I can give it a look today while Im at work..

    .zip it up though please.. =)

  5. #5
    Junior Member
    Join Date
    Jul 2004
    Posts
    19
    Ok, here you go. If you'd like, you can modify the PHP code to return the desired result, as shown above...
    Attached Files Attached Files

  6. #6
    Junior Member
    Join Date
    Jul 2004
    Posts
    19
    Oh, another thing, Whispers.
    I've tried all these things to get the scaling correct and it still doesn't do
    right. Check out
    http://www.listinventory.com/crimptoolsrotator.html

    The bottom one is how it is currently done on our site, but since I am trying to rotate several SWFs I need the rotator SWF to handle that.

    The other SWF that I load, the link is at the bottom of this post, scales perfectly for the stage in the rotator.

    How do I make sure the loaded clip(s) are scaled to the stage?

    container_mc.width = 715;
    container_mc._height = 90;
    this.stage.width = 715;
    this.stage.height= 90;
    this.stage.scaleMode = noScale;
    this.stage.scaleMode = exactFit;


    http://www.listinventory.com/file_up...ers/banner.swf

    We currently show 2 SWFs and "rotate" them using JavaScript but sometimes they bleed over one another.

    http://www.listinventory.com
    Last edited by MrBaseball34; 07-14-2010 at 09:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center