Solved

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

Posted on 2011-02-28
5
492 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
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): …
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

803 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