Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy to Bitmap loaded in sprite from Loader
    primarykey
    data
    text
    <p>i am trying to do the following: I want to load an external image (dest) and display it on the stage, and i want to load another image (src) which will not be visible. When i hold the left mouse button on the image that appears on the stage, then a function that start copies the src image to the dest will be invoked. Actually i want to reproduce the scratch effect on an image that hides another underneath. here is my code [ the copypixels function is triggered on mouse_move event for debug purposes ]</p> <p><code> package { import flash.display.Sprite; import flash.display.BitmapData; import flash.display.Loader; import flash.display.LoaderInfo; import flash.net.URLRequest; import flash.geom.Point; import flash.geom.Rectangle; import flash.events.Event; import flash.events.MouseEvent;</p> <pre><code>[SWF(width='400', height='300', backgroundColor='#ffffff', frameRate='24')] public class CopyDemo extends Sprite { private const BLADE_WIDTH:Number = 5; private const BLADE_HEIGHT:Number = 5; private var loadedSurpriseAssetContainer:Sprite; private var loadedSurpriseBitmapData:BitmapData; private var loadedFrontAssetContainer:Sprite; private var loadedFrontBitmapData:BitmapData; private var blade:Sprite; private var xmouse:Number; private var ymouse:Number; public function CopyDemo() { loadSurpriseImage("pic1.jpg"); } //-------- loadFrontImage ------------ private function loadFrontImage(url:String):void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onFrontLoaderComplete); loader.load(new URLRequest(url)); } //------- loadSurpriseImage ------------- private function loadSurpriseImage(url:String):void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSurpriseLoaderComplete); loader.load(new URLRequest(url)); } private function onFrontLoaderComplete(event:Event):void { loadedFrontAssetContainer = new Sprite(); loadedFrontAssetContainer.addChild(LoaderInfo(event.target).content); loadedFrontBitmapData = new BitmapData(loadedFrontAssetContainer.width, loadedFrontAssetContainer.height, true, 0x00000000); loadedFrontBitmapData.draw(loadedFrontAssetContainer); addChild(loadedFrontAssetContainer); loadedFrontAssetContainer.addEventListener(MouseEvent.MOUSE_MOVE, startcopy); } private function onSurpriseLoaderComplete(event:Event):void { loadedSurpriseAssetContainer = new Sprite(); loadedSurpriseAssetContainer.addChild(LoaderInfo(event.target).content); loadedSurpriseBitmapData = new BitmapData(loadedSurpriseAssetContainer.width, loadedSurpriseAssetContainer.height, true, 0x00000000); loadedSurpriseBitmapData.draw(loadedSurpriseAssetContainer); loadedSurpriseAssetContainer.addEventListener(MouseEvent.MOUSE_MOVE, saveCoords); loadFrontImage("pic2.jpg"); } private function saveCoords(event:MouseEvent):void { // } private function startcopy(event:MouseEvent):void { xmouse = mouseX; ymouse = mouseY; trace("x=" + xmouse + ", y=" + ymouse); loadedFrontBitmapData.copyPixels(loadedSurpriseBitmapData, new Rectangle(0,0,10,10), new Point(0,0)); } } </code></pre> <p>} </code></p> <p>Although the two images are loaded into memory and the first one is shown on the stage, when the mouse_move events triggers the corresponding handlers the copy does not work. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload