Flash CS5 : MovieClip Printing In AS3 - actionscript-3

I am facing some problem while printing an swf from another swf movie.
I have two movies, A & B, in which B will be loaded to A and will be printed from A using a Print btn in A. The swf B has many layers including vector and jpeg files. When I load the movie B to movie A it's coming properly, but when I try to print only the jpeg image which is in the top layer of B is coming. I tried printing area of stage, which is also giving the same result. What is the problem?
Here is the code:
print_btn.addEventListener(MouseEvent.CLICK,printContent);
function printContent(evt:MouseEvent) {
var printJob:PrintJob = new PrintJob();
if (printJob.start()) {
if (loader_mc.width>printJob.pageWidth) {
loader_mc.width=printJob.pageWidth;
loader_mc.scaleY=loader_mc.scaleX;
}
printJob.addPage(loader_mc);
printJob.send();
}
}
I've got the problem solved to some extent. Now the problem is that there is a movieclip in the second flash file which is converted to a perspective view using the 3D rotation tool and an image is attached dynamically to it. When I am printing, I am getting everything except the perspective view of the image or even the mc.

Try to render a new movieclip and then print that one:
var jpgSource:BitmapData = new BitmapData (width size, height size);
jpgSource.draw(your source movieclip);

Related

Starling - load SWF image(vector) into a Image

I'm trying to convert an old project of mine to use Starling for some extra performance.
I've come to a problem when I'm loading my SWFs and trying to display them.
Here is the code I used before: (no Starling)
private function swfLoaded(e:LoaderEvent):void {
var spr:Sprite = new Sprite();
spr = e.currentTarget.content;
bitmapData.draw(spr ...);
}
The problem when I'm using Starling is that the currentTarget.content is a flash.display.displayObject.
cannot convert com.greensock.loading.display::ContentDisplay#90ffec1 to starling.display.Sprite
I want to find a way to "convert" the flash.display.displayObject into a starling Sprite.
I also want to be able to store the loaded swfs content into a array as a sprite.
Thanks in advance,
Tompa
You're overwriting spr with a different value immediately after you create it, for one thing.
After you do the bitmapData.draw() call:
var tex:Texture = Texture.fromBitmapData(bitmapData, false, false);
The new texture can then be used to create a Starling Image sprite.

Cannot mask Stage3D SWF in Loader

Working in FlashBuilder, I build a mobile AS3 application that uses a Loader to display a local SWF file. It masks the loader so it only shows a 640x480 window. This worked fine using an old SWF file (a Flixel game, non-Stage3D).
I then tried it with a Stage3D-enabled SWF file. This failed to run, because the application was not set to run in the 'direct' renderMode (it had been in auto up until this point). This allowed the application to run, but the SWF file now ignores the Loader's mask and displays across the entire stage.
Is it not possible to mask Stage3D SWFs when loaded in this way? The loading looks like so:
public function FlixelTest()
{
super();
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
myLoader.x = (stage.fullScreenWidth-640)/2;
myLoader.y = (stage.fullScreenHeight-480)/2;
var url:URLRequest = new URLRequest("stage3dswf.swf"); // in this case both SWFs are in the same folder
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
myLoader.load(url); // load the SWF file
addChild(myLoader);
}
private function loadProdComplete(e:Event):void{
var gameMask : Shape = new Shape;
gameMask.graphics.beginFill(0xffcc00);
gameMask.graphics.drawRect(myLoader.x,myLoader.y,640,480);
gameMask.graphics.endFill();
myLoader.content.mask = gameMask;
}
As you can read in Adobe's documentation on Stage3D, the special Stage3D layers are located "behind" the regular stage used for 2D content.
Since any mask applied within the 2D stage exists in a different display list, there is no way to use 2D masks on Stage3D content. If at all possible, the only way to get similar results is to use 3D layers and alpha masks within the Stage3D context.

As3 Preloader (Blank until 100%)

I have an FLA file with two frames. On the first frame I have nothing but a textfield and some code to do the preloading. After it is done preloading it does gotoAndStop(2)
On frame 1 I have:
stop();
stage.scaleMode = StageScaleMode.SHOW_ALL;
//Import the required assets
import flash.display.*;
//Stop the playhead while loading occurs
this.stop();
//Create a listener to call the loading function as the movie loads;
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, PL_LOADING);
this.loaderInfo.addEventListener(Event.COMPLETE, PL_FINISH);
function PL_LOADING(event:ProgressEvent):void
{
var pcent:Number = event.bytesLoaded / event.bytesTotal * 100;
//Display the % loaded in textfield
txt.text = int(pcent) + "%";
//If the movie is fully loaded, kick to the next frame on the main timeline
}
function PL_FINISH(event:Event):void
{
removeChild(txt);
gotoAndStop(2);
}
On frame 2 I have nothing except:
var game:Game = new Game();
addChild(game);
In my publisher settings I have export to frame 2.
My problem is that the preloader won't display until 100%. Does anyone know why?
P.S. For testing I put a large image file on the stage in frame 2 and the result is the same.
This normally happens if you haven't deselected "Export in frame 1" in each of the library symbols that you are exporting for ActionScript.
You'll need to make sure that you create reference to these objects (so that ActionScript can access them) by placing them onto the stage in frame 2 (out of sight).
What's happening is that all of the symbols are being loaded before the preloader itself has loaded.
If this isn't the issue, then please provide some code so I can better assess your issue.
Have you tried putting something static on frame one? Just because there is a preloader, that doesn't mean that your swf will be displaying at all...
I know that I had one swf once which simply took a minute to actually get the Flex preloader to even show up because of network latency. It could be that your swf isn't displaying until 90% of it has already loaded.
I´m dealing with similar problems, and there is something i found out: my antivirus contains a kind of "browser protection" feature, which sort of checks all files in advance before it allows the browser to actually display them. If this antivirus feature has not been installed on the system, the preloader works beautifully. I´ve checked some other web-sites with flash content, and they also behave "wrong" under these circumstances. Now, some people seem to have found a way to stop the antivirus from messing around, but i don´t know how they do it... not yet...

Make mask visible in ActionScript 3.0

I have Loader object containing loaded swf. I don't know how the shape of this swf looks like - it's not necessarily rectangular.
I want to add some light reflection on it. I need to mask this reflection with Loader, but in the same time I need this Loader to be visible.
I don't want to load swf twice, because it may contain some dynamic, script-generated content, which can produce different results in each Loader.
And that's quite a problem, isn't it? Any ideas?
Image: http://www.freeimagehosting.net/uploads/12e6b9cd63.jpg
you could add your instance of the loaded swf to the stage, and for the reflection use he same movieclip/sprite and draw it to a new BitmapData. do the transformations needed and then add to stage.
Or imagine the following situation, instead of having the swf that is loaded adding it's own graphics to library you could do this from the loading application, so for instance, give the instance name of MyDisplayObject to the movieclip in the loaded swf and export to actionscript. After you load the swf you could use the following code to access the library, so you can add this object number of times you need, in you case 2.
here is the code (from adobe live docs)
function initHandler(e:Event) {
var applicationDomain:ApplicationDomain = e.target.applicationDomain; // e.target is the loaderInfo object
var testClip:Class=applicationDomain.getDefinition("testClip") as Class;
var clip = new testClip();
addChild(clip);
var reflection = new testClip();
addChild(reflection);
reflection.y= 100;
}
Hope this get's you on the right track.

When a SWF is loaded into another. Can the main SWF read the loaded one to retrieve its contents and modify them?

Give this scenario:
I have a cool graphic in Illustrator or Flash.
The graphic represents a figure, with various elements inside, shapes, lines, gradients, etc.
I export it to a swf file and I can view my nice graphic if I open it.
I have a (pure) as3 application, which loads swfs.
Then...
Can I manipulate the contents of the loaded swf. For example: Moving its contents, changing some elements inside, duplicating them. Deforming them with the transform matrix and things like that?
Can I, at least, read the contents and replicate them (the graphic data) inside the main application.
As far as I've been researching, I can only import the swf and use it as a whole display object, without any children, and I cannot modify it.
I want to, somehow, use the graphic information of the external swf to allow the main application deform it or use it to make new versions of the graphic.
No, sadly you can't retrieve or change compiled Graphics elements in detail, you can only use them as DisplayObjects and transform them through their public properties (scale, rotation, transform, etc...).
There is way of programmaticaly retrieve a single path coordinates by setting it as the "guide" of an object in the Flash IDE and within an onEnterFrame retrieve the object's position, but as you can imagine, its quite dirty.
You can replicate the clips by either setting them as classes within the loaded SWF (In Flash IDE: library>symbol>properties>export for AS) or using BitmapData to draw them as you please from the main movie.
Another solution would be to use a more open format, like SVG or FXG, but it can get quite complicated...
You can access loaded SWF's methods and properties if both are AVM2 movies.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
private function onLoadComplete(e:Event):void
{
var content:Object = LoaderInfo(e.target).content;
//assuming there is a public someMethod() defined in
//the document class of the loaded SWF, you can call it as:
content.someMethod();
//you can access any property you wish
content.someObject.graphics.beginFill(0x00ff00);
content.someObject.graphics.drawCircle(10, 10, 10);
content.someObject.graphics.endFill();
}
SWF content can be readed by new function added to Flash Player 11.6 and AIR 3.6:
flash.display.Grapics.readGraphicsData()
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#readGraphicsData%28%29
Similar problem:
How to read data from shape/graphics object