What is wrong with my code?
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: What is wrong with my code?

  1. #1
    Senior Member
    Join Date
    Feb 2004
    Posts
    113

    What is wrong with my code?

    hi there, i've tried to edit this code for a few days and it just wont work!
    Its supposed to create the new movie clip, then load in the image from the php results

    the php works fine and read the mysql perfectly! I think i'm just not calling the variable properly in the loop?

    the php gives lots of info...

    echo "&id" . $i . "=" . $cat["id"];
    echo "&name" . $i . "=" . $cat["name"];
    echo "&url1" . $i . "=" . $cat["url1"];
    echo "&url2" . $i . "=" . $cat["url2"];
    echo "&price" . $i . "=" . $cat["price"];

    Code:
    // Import the transitions classes so you can add a fading effect when the images load to the Stage.
    import mx.transitions.*;
    
    // Set the starting X and Y positions for the gallery images.
    _global.thisX = 30;
    _global.thisY = 70;
    
    /* Set static values for the Stage's width and height. 
       Using Stage.width and Stage.height within the code results in 
       strangely positioned full images when testing in the Flash environment 
       (but the problem doesn't exist when published to a SWF file). */
    _global.stageWidth = 600;
    _global.stageHeight = 400;
    
    
    /* create a function which loops through the images in an array,
       and creates new movie clips on the Stage. */
       
       
    function displayGallery(gallery_array:Array) {
    	var galleryLength:Number = gallery_array.length;
    	// loop through each of the images in the gallery_array.
    	function loadPictures() 
    
    {
    	myPictures = new LoadVars()
    	myPictures.load("getPictures.php") 
    	myPictures.onLoad = function(success)
    	{ 
    		if(success)
    		{ 
    	
    		for (var i = 0; i<galleryLength; i++) {
    		/* create a movie clip instance which holds the image. We'll also set a variable, 
    		   thisMC, which is an alias to the movie clip instance. */
    		
    		var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
    		
    		/* load the current image source into the new movie clip instance, 
    		   using the MovieClipLoader class. */
    		mcLoader_mcl.loadClip(myPictures["picName" + i], thisMC);
    		
    		// attach the preloader symbol from the Library onto the Stage.
    		preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
    		
    		/* set the preloader's bar_mc's _xscale property to 0% 
    		   and set a default value in the progress bars text field. */
    		preloaderMC.bar_mc._xscale = 0;
    		preloaderMC.progress_txt.text = "0%";
    		
    		// set the _x and _y coordinates of the new movie clip.
    		thisMC._x = _global.thisX;
    		thisMC._y = _global.thisY;
    		
    		// set the position of the image preloader.
    		preloaderMC._x = _global.thisX;
    		preloaderMC._y = _global.thisY+20;
    		
    		// if you've displayed 5 columns of images, start a new row.
    		if ((i+1)%5 == 0) {
    			// reset the X and Y positions
    			_global.thisX = 20;
    			_global.thisY += 80;
    		} else {
    			_global.thisX += 80+20;
    		}
    	}
    }
    
    // define the MovieClipLoader instance and MovieClipLoader listener Object.
    var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
    var mclListener:Object = new Object();
    mclListener.onLoadStart = function() {
    };
    
    // while the content is preloading, modify the width of the progress bar.
    mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
    	var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
    	// create a shortcut for the path to the preloader movie clip.
    	var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
    	preloaderMC.bar_mc._xscale = pctLoaded;
    	preloaderMC.progress_txt.text = pctLoaded+"%";
    };
    
    // when the onLoadInit event is thrown, you're free to position the instances 
    mclListener.onLoadInit = function(evt:MovieClip) {
    	evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
    	/* set local variables for the target movie clip's width and height,
    	   and the desired settings for the image stroke and border. */
    	var thisWidth:Number = evt._width;
    	var thisHeight:Number = evt._height;
    	var borderWidth:Number = 2;
    	var marginWidth:Number = 8;
    	evt.scale = 20;
    	// draw a white rectangle with a black stroke around the images.
    	evt.lineStyle(borderWidth, 0x000000, 100);
    	evt.beginFill(0xFFFFFF, 100);
    	evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
    	evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
    	evt.lineTo(thisWidth+borderWidth+marginWidth, thisHeight+borderWidth+marginWidth);
    	evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
    	evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
    	evt.endFill();
    	
    
    };
    loadPictures();
    stop();

  2. #2
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    i think its this bit thats wrong. Just can't get it to load the images form the php file

    myPictures = new LoadVars()
    myPictures.load("getPictures.php")
    myPictures.onLoad = function(success)
    {
    if(success)
    {

    for (var i = 0; i<galleryLength; i++) {
    /* create a movie clip instance which holds the image. We'll also set a variable,
    thisMC, which is an alias to the movie clip instance. */

    var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);

    /* load the current image source into the new movie clip instance,
    using the MovieClipLoader class. */
    mcLoader_mcl.loadClip(myPictures["picName" + i], thisMC);

  3. #3
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    i think its this bit thats wrong. Just can't get it to load the images form the php file

    myPictures = new LoadVars()
    myPictures.load("getPictures.php")
    myPictures.onLoad = function(success)
    {
    if(success)
    {

    for (var i = 0; i<galleryLength; i++) {
    /* create a movie clip instance which holds the image. We'll also set a variable,
    thisMC, which is an alias to the movie clip instance. */

    var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);

    /* load the current image source into the new movie clip instance,
    using the MovieClipLoader class. */
    mcLoader_mcl.loadClip(myPictures["picName" + i], thisMC);

  4. #4
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    bump

  5. #5
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
    correct me if I'm wrong, but "this" refers to myPictures which is a LoadVars instance.
    and you cannot call createEmptyMovieClip() on a LoadVars instance since it doesn't have that function.
    an alternative would be:
    var thisMC:MovieClip = _root.createEmptyMovieClip("image"+i+"_mc", i);
    or maybe:
    var thisMC:MovieClip = _parent.createEmptyMovieClip("image"+i+"_mc", i);
    Please sign here

  6. #6
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    Finally there are no more errors
    But it is just not drawing any images... i just get a blank flash page...

    here is my latest code. Am i missing something here?! ! I


    Code:
    // Import the transitions classes so you can add a fading effect when the images load to the Stage.
    import mx.transitions.*;
    
    // Set the starting X and Y positions for the gallery images.
    _global.thisX = 30;
    _global.thisY = 70;
    
    /* Set static values for the Stage's width and height. 
       Using Stage.width and Stage.height within the code results in 
       strangely positioned full images when testing in the Flash environment 
       (but the problem doesn't exist when published to a SWF file). */
    _global.stageWidth = 600;
    _global.stageHeight = 400;
    
    
    /* create a function which loops through the images in an array,
       and creates new movie clips on the Stage. */
       
    	var galleryLength:Number = gallery_array.length;
    	// loop through each of the images in the gallery_array.
    	function loadPictures() 
    {
    	myPictures = new LoadVars()
    	myPictures.load("getPictures.php") 
    	myPictures.onLoad = function(success)
    {
    	if(success)
    		{ 
    	
    		for (var i = 0; i<galleryLength; i++) {
    		/* create a movie clip instance which holds the image. We'll also set a variable, 
    		   thisMC, which is an alias to the movie clip instance. */
    		
    		var thisMC:MovieClip = _root.createEmptyMovieClip(myPictures["name"+i+"_mc"], i);
    		
    		/* load the current image source into the new movie clip instance, 
    		   using the MovieClipLoader class. */
    		mcLoader_mcl.loadClip(myPictures["url1" + i], thisMC);
    		
    		// attach the preloader symbol from the Library onto the Stage.
    		preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
    		
    		/* set the preloader's bar_mc's _xscale property to 0% 
    		   and set a default value in the progress bars text field. */
    		preloaderMC.bar_mc._xscale = 0;
    		preloaderMC.progress_txt.text = "0%";
    		
    		// set the _x and _y coordinates of the new movie clip.
    		thisMC._x = _global.thisX;
    		thisMC._y = _global.thisY;
    		
    		// set the position of the image preloader.
    		preloaderMC._x = _global.thisX;
    		preloaderMC._y = _global.thisY+20;
    		
    		// if you've displayed 5 columns of images, start a new row.
    		if ((i+1)%5 == 0) {
    			// reset the X and Y positions
    			_global.thisX = 20;
    			_global.thisY += 80;
    		} else {
    			_global.thisX += 80+20;
    		}
    	}
    }
    	}
    }
    // define the MovieClipLoader instance and MovieClipLoader listener Object.
    var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
    var mclListener:Object = new Object();
    mclListener.onLoadStart = function() {
    };
    
    loadPictures();
    stop();
    // while the content is preloading, modify the width of the progress bar.
    mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
    	var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
    	// create a shortcut for the path to the preloader movie clip.
    	var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
    	preloaderMC.bar_mc._xscale = pctLoaded;
    	preloaderMC.progress_txt.text = pctLoaded+"%";
    };
    
    // when the onLoadInit event is thrown, you're free to position the instances 
    mclListener.onLoadInit = function(evt:MovieClip) {
    	evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
    	/* set local variables for the target movie clip's width and height,
    	   and the desired settings for the image stroke and border. */
    	var thisWidth:Number = evt._width;
    	var thisHeight:Number = evt._height;
    	var borderWidth:Number = 2;
    	var marginWidth:Number = 8;
    	evt.scale = 20;
    	// draw a white rectangle with a black stroke around the images.
    	evt.lineStyle(borderWidth, 0x000000, 100);
    	evt.beginFill(0xFFFFFF, 100);
    	evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
    	evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
    	evt.lineTo(thisWidth+borderWidth+marginWidth, thisHeight+borderWidth+marginWidth);
    	evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
    	evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
    	evt.endFill();
    	
    
    };

    i ran another script i found which loads images from the same database and php i want to use for this script (but the actionscript just places images in already created boxes). and it works fine. so it is 100% a problem with my Action script in flash
    here is the test that works..
    http://www.nialma.com/pictures.swf

  7. #7

    why is it required ?

    why do you need this section

    * Set static values for the Stage's width and height.
    Using Stage.width and Stage.height within the code results in
    strangely positioned full images when testing in the Flash environment
    (but the problem doesn't exist when published to a SWF file). */
    _global.stageWidth = 600;
    _global.stageHeight = 400;



    ???



    http://www.hostingags.com

  8. #8
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    I don't think i need that line actually. I deleted it but it still just shows a blank page

  9. #9
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    bump

  10. #10
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    bump

  11. #11
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    bump

  12. #12
    Senior Member
    Join Date
    Feb 2004
    Posts
    113
    bump

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

Poll by Flashkit.com