Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-28
5
Medium Priority
?
504 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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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 how to load their YouTube profile onto Flash Media Live Encoder.
Suggested Courses

877 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