Solved

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

Posted on 2011-02-28
5
486 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

757 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

23 Experts available now in Live!

Get 1:1 Help Now