Solved

Export to jpeg movieclip from main timeline... not working

Posted on 2011-02-28
5
489 Views
Last Modified: 2012-06-27
Hello,
For 2 days I've been trying to figure out why my code to export a jpeg from a movieclip in Flash CS3/AS3 won't work.

I have one movieclip on my stage on frame 1
My code works perfectly if I reference a movieclip INSIDE the movie clip on my main timeline but when I try the main timeline movieclip, nothing happens.

Got to be a bug in my code somewhere... but where??

Below is the relevant code: the movieclip on my main timeline is 'mainmovie'.

If I change the code to reference a movieclip within it ie: mainmovie.headers_mc for example, it exports out the jpg of the headers_mc fine.

If it helps: all I'm trying to accomplish is a screenshot of the stage for a user to download. After much searching all I could find were ways to reference a movieclip and export it as a jpg. Thats why I moved all the content into a single movie clip on the main timeline.
var serverPath:String = "";

function createJPG(m:MovieClip, q:Number, fileName:String)
{
	var jpgSource:BitmapData = new BitmapData (m.width, m.height);
	jpgSource.draw(m);
	var jpgEncoder:JPGEncoder = new JPGEncoder(q);
	var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
	var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
	var jpgURLRequest:URLRequest = new URLRequest ( serverPath+"jpg_encoder_download.php?name=" + fileName + ".jpg");		
	jpgURLRequest.requestHeaders.push(header);				
	jpgURLRequest.method = URLRequestMethod.POST;				
	jpgURLRequest.data = jpgStream;
	
	var jpgURLLoader:URLLoader = new URLLoader();	
	//jpgURLLoader.load(jpgURLRequest);		
	navigateToURL(jpgURLRequest, "_blank");
}
	

brochure_btn.addEventListener(MouseEvent.CLICK, saveBtnPress);

function saveBtnPress(e:Event):void
{	
	createJPG(mainmovie, 90, "vehicle");
}

Open in new window

0
Comment
Question by:tjyoung
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
deepanjandas earned 500 total points
ID: 35003545
Try using stage instead of the mainmovie, like this:
 
var serverPath:String = "";

function createJPG(m:Stage, q:Number, fileName:String)
{
        var jpgSource:BitmapData = new BitmapData (m.stageWidth, m.stageHeight);
        jpgSource.draw(m);
        var jpgEncoder:JPGEncoder = new JPGEncoder(q);
        var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
        var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
        var jpgURLRequest:URLRequest = new URLRequest ( serverPath+"jpg_encoder_download.php?name=" + fileName + ".jpg");               
        jpgURLRequest.requestHeaders.push(header);                              
        jpgURLRequest.method = URLRequestMethod.POST;                           
        jpgURLRequest.data = jpgStream;
        
        var jpgURLLoader:URLLoader = new URLLoader();   
        //jpgURLLoader.load(jpgURLRequest);             
        navigateToURL(jpgURLRequest, "_blank");
}
        

brochure_btn.addEventListener(MouseEvent.CLICK, saveBtnPress);

function saveBtnPress(e:Event):void
{       
        createJPG(stage, 90, "vehicle");
}

Open in new window


Warm Regards
Deepanjan Das
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35003547
I guess, the width and height of mainmovie is coming as 0.

Warm Regards
Deepanjan Das
0
 
LVL 1

Author Comment

by:tjyoung
ID: 35007310
Hi,
No that doesn't seem to make any difference for some reason. Just does nothing after clicking the button. i'm not sure but I don't think you can make a bitmap out of simply the stage which is why I went with a movieclip. Would have been easier if I could have but it seems to me I read somewhere you can't.

Like I mentioned it works perfectly when referencing a movieclip within the movieclip on the main timeline, just not the movie clip on the main timeline.
0
 
LVL 1

Author Comment

by:tjyoung
ID: 35007336
I also tried keeping the mainmovie in as the target and setting an x and y height.
Same thing, no difference. Nothing happens when clicking.
Any idea how I can debug with trace?
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35013842
First of all. you can make snapshot from stage, kindly refer to this article here.

I would rather request you to share your file to see, if there are any other stuff that's blocking it.

Warm Regards
Deepanjan Das
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now