# AS bridge

**URL:** <https://forum.kirupa.com/t/as-bridge/323516>\
**Category:** Uncategorized\
**Created:** [July 5, 2011, 10:10am UTC](https://forum.kirupa.com/t/as-bridge/323516 "2011-07-05T10:10:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrelusive](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@mrelusive](https://forum.kirupa.com/u/mrelusive)\
**Post date:** [July 5, 2011, 10:10am UTC](https://forum.kirupa.com/t/as-bridge/323516/1 "2011-07-05T10:10:52Z")

</div>

I think someone who are good in AS can help me in very short time, maby this is look like big text but it is not.  
My problem is:

- I have two buttons, one in AS2 and the other one in AS3 window.
- Buttons doing different job.
- Is it possibile when i click on button in AS2 to do also what button in AS3 doing.?
- Mean: Separately both button work fine. I want when click in AS2 button both event to start, if you understand what i’m saying.  
I don’t know how to do that, i am not good as you.  
Can you please help me?

Now better explanation:

This is a code I used in AS3 file from this adress:

> **[Save JPG /PNG image from AS2 project using AS3 & PHP](http://blog.crondesign.com/2009/10/save-large-image-jpg-png-from-as2.html?showComment=1309790792103#c6180543047582176214)**
>
> There's a tonne of Actionscript 2 image capture scripts out there but after an extensive search last month, the best ones I could find all r...

[COLOR=blue]AS3 code:[/COLOR]

```auto
import com.adobe.images.JPGEncoder; import nl.stroep.utils.*; import com.gskinner.utils.SWFBridgeAS3; //SETUP:::::::::::::::: loadingsign.visible=false var scriptURL="http://www.my_website.com/"; //absolute path to directory containing savePNG.php on your server var savePath="my_picture"; // save filename excluding .png file extension (relative path from scriptURL) var scriptName="savePNG.php" var AS2swf="my_AS2_file.swf" /////////////////////// //LOAD THE AS2 swf: loadingsign.visible=false var loadit = new Loader(); loadit.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete); addChild(loadit); loadit.load(new URLRequest(AS2swf)); //the name of your AS2 swf //when swf has loaded: function onLoadComplete(evt:Event):void { //move print button and loading sign above imported swf: setChildIndex(goBTN, numChildren-1); setChildIndex(loadingsign, numChildren-1); trace('AS2 LOADED') } ///SET UP A BRIGE TO AS2: var myBridge:SWFBridgeAS3 = new SWFBridgeAS3("connectionID", this); /* //WHEN THE CONNECTION IS ESTABLISHED: (optional) myBridge.addEventListener(Event.CONNECT, handleConnect); function handleConnect(event:Event){ //setupSWF is an example how to call an AS2 custom function: myBridge.send("setupSWF","parameter1"); }; */ //PRINT BUTTON ACTION: goBTN.addEventListener(MouseEvent.MOUSE_UP, goBTNclick); function goBTNclick(event:Event){ loadingsign.visible=true goPrint(112,1,867,530) } //CREATE AND EXPORT THE JPGS TO PHP: function goPrint(X:Number,Y:Number,W:Number,H:Number){ var thecrop = crop( stage,W,H,X,Y); var imageSaver:ImageSaver = new ImageSaver( scriptURL+scriptName ); imageSaver.save ( thecrop, savePath ); imageSaver.addEventListener ( Event.COMPLETE,onSaveComplete) imageSaver.addEventListener ( IOErrorEvent.IO_ERROR, onSaveError ); trace('PRINTING: '+X+', '+Y+', '+W+', '+H+" to:
"+scriptURL+savePath+'.png'); } function onSaveComplete(e){ trace('SAVE COMPLETE') loadingsign.visible=false } function onSaveError(e){ trace('ERROR WITH SAVE') loadingsign.visible=false } ///////////////////// //FUNCTIONS:::::::::: function crop( inDisplayObject:DisplayObject, inWidth:Number = 550, inHeight:Number = 400, inX:Number = 0, inY:Number = 0, inScale:Number = 1):Bitmap{ if (!inDisplayObject) { throw new Error('CropUtil.crop > needs a something on the display list'); return null; } var cropArea:Rectangle = new Rectangle( 0, 0, inWidth * inScale, inHeight * inScale); var croppedBitmap:Bitmap = new Bitmap( new BitmapData( inWidth * inScale, inHeight * inScale), PixelSnapping.ALWAYS, true ); croppedBitmap.bitmapData.draw( inDisplayObject, new Matrix(inScale, 0, 0, inScale, -inX, -inY), null, null, cropArea, true ); return croppedBitmap; }

```

[COLOR=blue]AS2 code:[/COLOR]

```auto
//AS2-3 bridge: import com.gskinner.utils.SWFBridgeAS2; var myBridge:SWFBridgeAS2 = new SWFBridgeAS2("connectionID", this);

```

goBTN is name of the instance in AS3 file. When I click in the that button picture is saved on the server.

My problem is I want to have a button in AS2 file, and when i click on that button to do action like AS3 button.

I’m trying this for a long time and couldn’t make it to work.  
Can somebody help me. Here is the link i found closer to problem:

> **[SWFBridge: Easier AS3 to AS2 Communication - gskinner blog](http://blog.gskinner.com/archives/2007/07/swfbridge_easie.html)**
>
> SWFBridge makes establishing two way communication between SWFs via LocalConnection much easier. This is useful for talking between different SWFs embedded on the same HTML page, but especially for communicating between an ActionScript 3 application...
