Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

830 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