Printing loadmovie

  • tarafenton
  • Novice
  • Novice
  • tarafenton
  • Posts: 19
  • Loc: Fort Lauderdale, FL USA

Post 3+ Months Ago

Hello,
I am trying to print a loaded movie. But I print a black page.

Code: [ Select ]
my_print.onRelease = function(){ 
var my_pj:PrintJob = new PrintJob();
var myResult:Boolean = my_pj.start();
 if(myResult) {
  for(var w=0; w<sortedInput.length; w++){
   loadMovie("printImages/"+sortedInput[w]+".swf", "holder_mc");
   
   my_pj.addPage("holder_mc");
  }
  my_pj.send();
 }
delete my_pj;
}
  1. my_print.onRelease = function(){ 
  2. var my_pj:PrintJob = new PrintJob();
  3. var myResult:Boolean = my_pj.start();
  4.  if(myResult) {
  5.   for(var w=0; w<sortedInput.length; w++){
  6.    loadMovie("printImages/"+sortedInput[w]+".swf", "holder_mc");
  7.    
  8.    my_pj.addPage("holder_mc");
  9.   }
  10.   my_pj.send();
  11.  }
  12. delete my_pj;
  13. }


Any suggestions are greatly appreciated!
Tara
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Honestly I have never worked with this, but my guess (from what it looks like) is that your external movie isn't fully loaded before you start printing.
  • tarafenton
  • Novice
  • Novice
  • tarafenton
  • Posts: 19
  • Loc: Fort Lauderdale, FL USA

Post 3+ Months Ago

Good guess, that was were I was headed. I tried this.
Code: [ Select ]
my_print.onRelease = function(){    
var my_pj:PrintJob = new PrintJob();
var myResult:Boolean = my_pj.start();
 if(myResult) {
    for(var w=0; w<sortedInput.length; w++){
        loadMovie("printImages/"+sortedInput[w]+".swf", "holder_mc");

        if(holder_mc.getBytesLoaded = holder_mc.getBytesTotal ){
            trace("i made it to the bytes loaded statement");
        my_pj.addPage("holder_mc");
        }
    }
    my_pj.send();
 }
delete my_pj;
}
  1. my_print.onRelease = function(){    
  2. var my_pj:PrintJob = new PrintJob();
  3. var myResult:Boolean = my_pj.start();
  4.  if(myResult) {
  5.     for(var w=0; w<sortedInput.length; w++){
  6.         loadMovie("printImages/"+sortedInput[w]+".swf", "holder_mc");
  7.         if(holder_mc.getBytesLoaded = holder_mc.getBytesTotal ){
  8.             trace("i made it to the bytes loaded statement");
  9.         my_pj.addPage("holder_mc");
  10.         }
  11.     }
  12.     my_pj.send();
  13.  }
  14. delete my_pj;
  15. }


But now a blank page is printed
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

You aren't running your byte check in an onEnterFrame and I'm assuming my_pj.send() is what actually starts thr PrintJob.. and that isn't in your if statement.

And aside from that, you would need to do an individual check on each of the clips loading something. to make sure they are all loaded. Since you aren't loading to holder_mc directly, it will always return true in that statement.

And getBytesLoaded() and getBytesTotal() require the () at the end.


[edit]
wait... lol... maybe i should have looked closer at your code.

You can't load multiple movies to one clip... the one loading will just keep overwriting the one before it.
  • tarafenton
  • Novice
  • Novice
  • tarafenton
  • Posts: 19
  • Loc: Fort Lauderdale, FL USA

Post 3+ Months Ago

I'm almost there. At least now it is printing the image that is loaded. But if I sent more than one, it only sends the last one. Your helpful suggestions have gotten me this far, do you have any more? I tried the bits loaded but went crazy with the enterframe logic. can i put the onPress and onRelease in a for loop? [edit] NOPE

Code: [ Select ]
my_print.onPress = function(){    
    for(var w=0; w<sortedInput.length; w++){
            loadMovieNum("printImages/"+sortedInput[w]+".swf", 3+w);
    }
}
my_print.onRelease = function(){
    var my_pj:PrintJob = new PrintJob();
    var myResult:Boolean = my_pj.start();
     if(myResult) {
        for(var w=0; w<sortedInput.length; w++){            
            my_pj.addPage(3+w);
            my_pj.send();
            }
            }            
            delete my_pj;
}
  1. my_print.onPress = function(){    
  2.     for(var w=0; w<sortedInput.length; w++){
  3.             loadMovieNum("printImages/"+sortedInput[w]+".swf", 3+w);
  4.     }
  5. }
  6. my_print.onRelease = function(){
  7.     var my_pj:PrintJob = new PrintJob();
  8.     var myResult:Boolean = my_pj.start();
  9.      if(myResult) {
  10.         for(var w=0; w<sortedInput.length; w++){            
  11.             my_pj.addPage(3+w);
  12.             my_pj.send();
  13.             }
  14.             }            
  15.             delete my_pj;
  16. }

TIA,
Tara
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

This is how I would write it... given what you have showed me and that fact that I have never worked with PrintJob before.

Code: [ Select ]
var loaded:Number = 0;
my_print.onRelease = function() {
    var my_pj:PrintJob = new PrintJob();
    var myResult:Boolean = my_pj.start();
    if (myResult) {
        for (var w = 0; w<sortedInput.length; w++) {
            container = holder_mc.createEmptyMovieClip("container"+w, w);
            //create preloader clip
            preloader = holder_mc.createEmptyMovieClip("preloader"+w, w+1000);
            //define which clip should get preloaded
            preloader.targ = container;
            container.loadMovie("printImages/"+sortedInput[w]);
            //run preloader
            preloader.onEnterFrame = function() {
                if (this.targ.getBytesLoaded()>=this.targ.getBytesTotal() && this.targ._width>0) {
                    //if clip is loaded, increment the variable to check if all are loaded
                    loaded++;
                    //remove the preloader clip, it's no longer needed
                    this.removeMovieClip();
                }
            };
        }
    }
    this.onEnterFrame = function() {
        //if all the movies are loaded
        if (loaded>=sortedInput.length) {
            my_pj.addPage("holder_mc");
            my_pj.send();
            delete my_pj;
        }
    };
};
  1. var loaded:Number = 0;
  2. my_print.onRelease = function() {
  3.     var my_pj:PrintJob = new PrintJob();
  4.     var myResult:Boolean = my_pj.start();
  5.     if (myResult) {
  6.         for (var w = 0; w<sortedInput.length; w++) {
  7.             container = holder_mc.createEmptyMovieClip("container"+w, w);
  8.             //create preloader clip
  9.             preloader = holder_mc.createEmptyMovieClip("preloader"+w, w+1000);
  10.             //define which clip should get preloaded
  11.             preloader.targ = container;
  12.             container.loadMovie("printImages/"+sortedInput[w]);
  13.             //run preloader
  14.             preloader.onEnterFrame = function() {
  15.                 if (this.targ.getBytesLoaded()>=this.targ.getBytesTotal() && this.targ._width>0) {
  16.                     //if clip is loaded, increment the variable to check if all are loaded
  17.                     loaded++;
  18.                     //remove the preloader clip, it's no longer needed
  19.                     this.removeMovieClip();
  20.                 }
  21.             };
  22.         }
  23.     }
  24.     this.onEnterFrame = function() {
  25.         //if all the movies are loaded
  26.         if (loaded>=sortedInput.length) {
  27.             my_pj.addPage("holder_mc");
  28.             my_pj.send();
  29.             delete my_pj;
  30.         }
  31.     };
  32. };


I can't guarantee it will work (I don't have means to test it), but it's all I got and I hope it points you in the right direction if it doesn't work.
  • tarafenton
  • Novice
  • Novice
  • tarafenton
  • Posts: 19
  • Loc: Fort Lauderdale, FL USA

Post 3+ Months Ago

Thanks lostinbeta, for all of your suggestions. unfortunately your suggested code didn't do what I needed, but thankfully I went back to my code that almost worked and move the send() out of the if statement and everything is working perfectly. :D


Code: [ Select ]
my_print.onPress = function(){        
        for(var w=0; w<sortedInput.length; w++){
            loadMovieNum("printImages/"+sortedInput[w]+".swf", 3+w);
    }
}
my_print.onRelease = function(){
    var my_pj:PrintJob = new PrintJob();
    var myResult:Boolean = my_pj.start();
     if(myResult) {
        for(var w=0; w<sortedInput.length; w++){
            my_pj.addPage(3+w);            
            }
            my_pj.send();
            }            
            delete my_pj;
}
  1. my_print.onPress = function(){        
  2.         for(var w=0; w<sortedInput.length; w++){
  3.             loadMovieNum("printImages/"+sortedInput[w]+".swf", 3+w);
  4.     }
  5. }
  6. my_print.onRelease = function(){
  7.     var my_pj:PrintJob = new PrintJob();
  8.     var myResult:Boolean = my_pj.start();
  9.      if(myResult) {
  10.         for(var w=0; w<sortedInput.length; w++){
  11.             my_pj.addPage(3+w);            
  12.             }
  13.             my_pj.send();
  14.             }            
  15.             delete my_pj;
  16. }
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

SWEEEEET!

I'm glad you got it working!

Does it work if you upload it to a server though? Is this going to be on a server?

The reason I ask is because if you test locally, the files load almost instantaneously.... but if you upload them on a server they have to download... so there will be a delay... which is why I was mentioning about preloading the files.
  • tarafenton
  • Novice
  • Novice
  • tarafenton
  • Posts: 19
  • Loc: Fort Lauderdale, FL USA

Post 3+ Months Ago

Yeah, your right when i uploaded it didn't work as well as it did from my computer. I've been playing around with it, but I can't get it to work. So I'm using the MovieClipLoader() and added myListener.onLoadComplete (both actions are new to me), and it seems that I am back to square one.:( Can you help me think out the logic for this script?

Code: [ Select ]
/////////////////  PRINT FUNCTION //////////////////////////
var myMCL = new MovieClipLoader(); //define MovieClipLoader
var myListener = new Object();   //define listener
var page:Number=-1;
function initClips(){
    for (i=0; i<sortedInput.length; i++){
        this.attachMovie("img", "img" + i, i);
         this["img"+i]._x = i*110;
        myMCL.loadClip("printImages/"+sortedInput[i]+".swf" , this["img"+i]);
    }    
}
myListener.onLoadComplete = function(targetMC){
    trace("page: "+page);
    if(page==-1){
        var my_pj:PrintJob = new PrintJob();
        var myResult:Boolean = my_pj.start();
        trace(myResult);
        page=page+1;
    }
        page=page+1;
        trace("i: "+i);
        trace("page: "+page);
        trace("targetMC._name: "+targetMC._name);
        my_pj.addPage(targetMC._name);
        if(page==i){
        trace("i made it in the double check");
        my_pj.send();
        page=page+1;
        trace("page after send to print: "+page);
        }
        if(page==(i+1)){
            trace("i made it in the delete");
        delete my_pj;
    }
        
    }
    
my_print.onPress = function(){    
    myMCL.addListener(myListener);
    initClips();
}
my_print.onRelease = function(){    
    trace("i in onRelease: "+i);
    trace("page in onRelease: "+page);
    
    
        
}
  1. /////////////////  PRINT FUNCTION //////////////////////////
  2. var myMCL = new MovieClipLoader(); //define MovieClipLoader
  3. var myListener = new Object();   //define listener
  4. var page:Number=-1;
  5. function initClips(){
  6.     for (i=0; i<sortedInput.length; i++){
  7.         this.attachMovie("img", "img" + i, i);
  8.          this["img"+i]._x = i*110;
  9.         myMCL.loadClip("printImages/"+sortedInput[i]+".swf" , this["img"+i]);
  10.     }    
  11. }
  12. myListener.onLoadComplete = function(targetMC){
  13.     trace("page: "+page);
  14.     if(page==-1){
  15.         var my_pj:PrintJob = new PrintJob();
  16.         var myResult:Boolean = my_pj.start();
  17.         trace(myResult);
  18.         page=page+1;
  19.     }
  20.         page=page+1;
  21.         trace("i: "+i);
  22.         trace("page: "+page);
  23.         trace("targetMC._name: "+targetMC._name);
  24.         my_pj.addPage(targetMC._name);
  25.         if(page==i){
  26.         trace("i made it in the double check");
  27.         my_pj.send();
  28.         page=page+1;
  29.         trace("page after send to print: "+page);
  30.         }
  31.         if(page==(i+1)){
  32.             trace("i made it in the delete");
  33.         delete my_pj;
  34.     }
  35.         
  36.     }
  37.     
  38. my_print.onPress = function(){    
  39.     myMCL.addListener(myListener);
  40.     initClips();
  41. }
  42. my_print.onRelease = function(){    
  43.     trace("i in onRelease: "+i);
  44.     trace("page in onRelease: "+page);
  45.     
  46.     
  47.         
  48. }

TIA,
Tara
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Those functions are new to me too :-\

I just upgraded to Flash MX 2004... I am a total ActionScript 2.0 newbie and have no idea how MovieClipLoader works.

*feels lame*


Maybe it doesn't work because you are using 1 moviecliploader object to check the load of multiple items at the same time. I believe you can re-use a MovieClipLoader object for different things as long as it isn't at the same time, but it looks to me like it might possibly be attaching itself to just the last movie getting loaded.
  • tarafenton
  • Novice
  • Novice
  • tarafenton
  • Posts: 19
  • Loc: Fort Lauderdale, FL USA

Post 3+ Months Ago

Okay, I think that I solved my issues and I wanted to post my findings just in case someone reads this later on.
What I did was load the movies as soon as the movie started, BUT the alpha is set to 0 so that no one sees it until they press the print button, then the alpha is set to 100(because if the alpha is still set to 0, the images will not print),
then they are sent to the printer, and then the movie unloads. The images are there for a flash, I might put a dummy graphic the same as the background color, to fix that.
In my findings, on the live docs for the printjob function, it mentions that you can't talk to flash while it is in the middle of the print job, so how I was trying to do it before would never work. I had to keep the addPage within the myResult statement. I know that this may not be the most precise way of competing my task. But hey it worked. Thanks to you lostinbeta for getting me through this maddness. Now it works even when it is uploaded to the server. Once we go live I'll post the link so you can see what it is and how it works. Thanks again,
Tara
Code: [ Select ]
var myMCL = new MovieClipLoader(); //define MovieClipLoader
var myListener = new Object();   //define listener
  for(var w=0; w<sortedInput.length; w++){
          this.attachMovie("img", "img" + w, w+1000);
         this["img"+w]._alpha = 0;//load the images invisible
        myMCL.loadClip("printImages/"+sortedInput[w]+".swf" , this["img"+w]);
  }
my_print.onPress = function(){
    for(var w=0; w<sortedInput.length; w++){         
         _root["img"+w]._alpha = 100;//make the images visible before printing
    }
}
my_print.onRelease = function(){
  var my_pj:PrintJob = new PrintJob();
  var myResult:Boolean = my_pj.start(); //print the images
   if(myResult) {
   for(var w=0; w<sortedInput.length; w++){     
     my_pj.addPage("img"+w);        
         }
     my_pj.send();
     }       
     delete my_pj;
         unloadMovieNum(2);
}
  1. var myMCL = new MovieClipLoader(); //define MovieClipLoader
  2. var myListener = new Object();   //define listener
  3.   for(var w=0; w<sortedInput.length; w++){
  4.           this.attachMovie("img", "img" + w, w+1000);
  5.          this["img"+w]._alpha = 0;//load the images invisible
  6.         myMCL.loadClip("printImages/"+sortedInput[w]+".swf" , this["img"+w]);
  7.   }
  8. my_print.onPress = function(){
  9.     for(var w=0; w<sortedInput.length; w++){         
  10.          _root["img"+w]._alpha = 100;//make the images visible before printing
  11.     }
  12. }
  13. my_print.onRelease = function(){
  14.   var my_pj:PrintJob = new PrintJob();
  15.   var myResult:Boolean = my_pj.start(); //print the images
  16.    if(myResult) {
  17.    for(var w=0; w<sortedInput.length; w++){     
  18.      my_pj.addPage("img"+w);        
  19.          }
  20.      my_pj.send();
  21.      }       
  22.      delete my_pj;
  23.          unloadMovieNum(2);
  24. }

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 17 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.