1 Reply Latest reply on May 5, 2007 10:13 PM by Optikalefx

    Identical actionscript works in one frame but not another...?

    iamali84
      Hi all,

      I'm working on this electronic sheep creator for my Masters degree (don't ask haha..) which is online at [url]www.aegreen.co.uk/creativetech/[/url] . The problem I'm having is that a piece of actionscript I'm using for saving the sheep as a jpg using BitmapData works in one frame with one movie clip but not in another frame..

      In frame 1 I create two movie clips - mc_modifysheep and mc_dna:

      [CODE]on(release) {
      _root.createEmptyMovieClip("mc_modifysheep", 1)
      mc_modifysheep._x = 150;
      mc_modifysheep._y = 70;
      mc_modifysheep.attachMovie("sheep_body", "body", 1, {_x:42, _y:65});
      mc_modifysheep.attachMovie("sheep_head", "head", 2, {_x:0, _y:0});
      mc_modifysheep.attachMovie("sheep_legs", "legs", 3, {_x:77, _y:215});
      _global.bodycolour = "default";
      _global.headcolour = "default";
      _global.legscolour = "default";

      _root.createEmptyMovieClip("mc_dna", 2)
      mc_dna._x = 0;
      mc_dna._y = 0;
      mc_dna.attachMovie("mc_DNA_empty", "DNA empty", 1, {_x:8, _y:360});
      mc_dna.attachMovie("mc_dna_default_default_top", "top", 2, {_x:45, _y:374});
      mc_dna.attachMovie("mc_dna_default_default_right", "right", 3, {_x:65, _y:400});
      mc_dna.attachMovie("mc_dna_default_default_left", "left", 4, {_x:32, _y:401});

      gotoandstop(2);
      }[/CODE]

      the sheep in 'mc_modifysheep' and the dna in 'mc_dna' are built up over frames 2 and 3 and then in frame 4 the user decides whether the sheep is given freedom or captivity. If freedom is chosen then the user is prompted to name their sheep and the movie clip mc_modifysheep is saved as a jpg on the server using BitmapData and PHP. If captivity is chosen then the user is prompted to name the dna and the movie clip mc_dna is meant to be saved as a jpg on the server but only a white blank jpg is produced, not what is contained in mc_dna.. I've tried all sorts but I can't figure out why it's doing this..

      Here's the code I'm using, that works, to save the mc_modifysheep:

      [CODE]import flash.display.BitmapData;
      btn_freedom.onPress = function() {
      freedom();
      };

      function freedom() {
      snap_sheep = new BitmapData(305, 290);
      snap_sheep.draw(mc_modifysheep);

      var pixels:Array = new Array();
      var w:Number = snap_sheep.width;
      var h:Number = snap_sheep.height;
      var a:Number = 0;

      var sn:String = txt_Freedom.text;
      high = 99999;
      low = 00000;
      ran = Math.floor(Math.random()*(Number(high)+1-Number(low)))+Number(low);
      var rn:Number = ran
      var filename:String = dn+sn;

      for (var a = 0; a <= w; a++) {
      for (var b = 0; b <= h; b++) {
      var tmp = snap_sheep.getPixel(a, b).toString(16);
      pixels.push(tmp);
      }
      }

      var freedomoutput:LoadVars = new LoadVars();
      freedomoutput.img = pixels.toString();
      freedomoutput.height = h;
      freedomoutput.width = w;
      freedomoutput.filename_sheep = filename;
      freedomoutput.send("save_sheep.php", "_self", "POST");
      }
      stop();[/CODE]

      and here's the near identical code apart from different variable/movieclip names I'm using to try and save (but failing) mc_dna:

      [CODE]import flash.display.BitmapData;
      btn_capt.onPress = function() {
      capt();
      };

      function capt() {
      snap_dna = new BitmapData(305, 290);
      snap_dna.draw(mc_dna);

      var pixels:Array = new Array();
      var w:Number = snap_dna.width;
      var h:Number = snap_dna.height;
      var a:Number = 0;

      var dn:String = txt_Capt.text;
      high = 99999;
      low = 00000;
      ran = Math.floor(Math.random()*(Number(high)+1-Number(low)))+Number(low);
      var rn:Number = ran
      var filename:String = dn+rn;

      for (var a = 0; a <= w; a++) {
      for (var b = 0; b <= h; b++) {
      var tmp = snap_dna.getPixel(a, b).toString(16);
      pixels.push(tmp);
      }
      }

      var captoutput:LoadVars = new LoadVars();
      captoutput.img = pixels.toString();
      captoutput.height = h;
      captoutput.width = w;
      captoutput.filename_dna = filename;
      captoutput.send("save_dna.php", "_self", "POST");
      }
      stop();[/CODE]

      I know it's a problem with the flash and not the PHP as I've tested for that, definately in the flash. I just don't understand how the same code can capture mc_modifysheep, but not mc_dna. argh!!!

      If you need to take a look at the FLA file it's up at [url]www.aegreen.co.uk/creativetech/dohumansdream.fla[/url]

      Thanks everyone!!
        • 1. Re: Identical actionscript works in one frame but not another...?
          Optikalefx Level 1
          If you dont find anything specific, a lot of the problems i encounter like this are because one little thing is spelled wrong. like it doesnt match whats in your php file, ect. my suggestion, though a long one, if you know its supposed to work, and theres no syntax error, re type it, not copy and paste, and just be careful. keep tripple checking. you might not even find what was spelled wrong, but it might fix the situation,