var splits:Number = 100;
var splitWidth:Number = Math.round(imageOnScreen.width / splits);
var splitHeight:Number = Math.round(imageOnScreen.height / splits);
var newCopy:BitmapData = new BitmapData(imageOnScreen.width,imageOnScreen.height);
newCopy.draw(imageOnScreen);
for (var i = 0; i < splits; i++)
{
this["bmd" + i] = new BitmapData(imageOnScreen.width,imageOnScreen.height,true,0);
this["bmd" + i].copyPixels(newCopy,new Rectangle(i * splitWidth,0,splitWidth,imageOnScreen.height), new Point(0,0));
this["bm" + i] = new Bitmap(this["bmd" + i]);
addChild(this["bm"+i]);
this["bm" + i].x = i * (splitWidth + 1);
}
// make original image hidden to see copy
imageOnScreen.visible = false;
Any help is advise for me.
If you can help with making copied file transparent pixel, any help great. thank
here file too
Not sure what you mean. Why are you making it into squares? Is it a visual thing?
Do traces on your numbers to see what you're doing.
this["bmd" + i].copyPixels(newCopy,new Rectangle(i * splitWidth,splitHeight,splitWidth,MyImage.height), new Point(0,0));
trace("splitWidth: " + splitWidth + " splitHeight" + splitHeight);
You can use modulo to get the y of a grid.
You can do whatever you want using bitmap-free regular flash and "draw" the movieclip to bitmapdata.
var DropShadow1:DropShadowFilter = new DropShadowFilter(0,45,0x000000,1,2,2,1,1);
var NewImagePiece:Bitmap = new Bitmap();
var Spr:Sprite = new Sprite();
var MyOrignalImage:*;
var MyImage:*;
var Pieces:Array = new Array();
var SplitWidth:Number;
var SplitHeight:Number;
var Splits:Number = 5;
// *** loader
// *** attach loader bar
var LBar:LoaderBar = new LoaderBar();
LBar.x = 10;
LBar.y = 10;
function DoSplit()
{
MyImage = MyLoader.content;
var SplitWidth:Number = Math.ceil(MyImage.width / Splits);
var SplitHeight:Number = Math.ceil(MyImage.height / Splits);
var NewCopyImage:BitmapData = new BitmapData(MyImage.width,MyImage.height,true,0x00FFFFFF);
NewCopyImage.draw(MyImage);
for (var i = 0; i < Splits; i++)
{
for (var j = 0; j < Splits; j++)
{
var Spr:Sprite = new Sprite();
addChild(Spr);
var NewImage:BitmapData = new BitmapData(SplitWidth,SplitHeight,true,0x00FFFFFF);
NewImage.copyPixels(NewCopyImage,new Rectangle(i * SplitWidth,j * SplitHeight,SplitWidth,SplitHeight), new Point(0,0));
var NewImagePiece:Bitmap = new Bitmap(NewImage);
NewImagePiece.name = "NewImagePiece" + i;
function Drag(e:MouseEvent)
{
this.parent.addChild(this);
e.currentTarget.startDrag();
trace(e.currentTarget.name);
}
function NoDrag(e:MouseEvent)
{
e.currentTarget.stopDrag();
}
// *** working on this
function Animate(event:Event)
{
// move the pieces;
if (! Pieces.length)
{
trace("DONE!");
removeEventListener(Event.ENTER_FRAME, Animate);
}
}
if you can help me animate the pieces also or guide me
Looked at the last two examples. Do you program in something else? Youre figuring it out. Most of the issues, programming issues like depth and how your code is structured, fall under oop. If you do a couple hours on an intro to oop (in general, not actionscript), you'll see how oop-based flash and everything else is and that everybody doing flash is doing oop whether they know it or not.
Have you created clips by hand on the stage in layers? If not, you definitely should because you can physically work with the objects created by actionscript and depths. Plus, it's far more efficient to design on the stage - you don't have to compile the swf to see things.
You should use clips as containers for other clips for everything. For example, if I'm going to show a jpg, the jpg loader gets added to something like picHolder.pic and picHolder is added to stage.
Use camelCase for your var/function names. Uppercase first letter means it's a class. I personally just use camelCase but employers may require you to use proper oop naming conventions.
Your drag function shouldn't have the code about adding itself to the stage or whatever.
You can store everything in arrays of objects.
var oTemp:Object;
var oTemp = new Object();
var oTemp.stringWhatever = "asdfas";
var oTemp.intID = 32;
myArray.push(oTemp);
trace(myArray[0].intID);
You can use classes, your code is close already. Open a new as3 file in flash, save it, under Publish, fill in Class with Main (the name of your main class), hit the pencil button to right, and flash will create a new class Main, save it in same folder as your fla and you have a working class.
You can also put your regular as code in an external actionscript .as file for easier editing. Here's command to include external:
include "main.as"
var dropShadow1:DropShadowFilter = new DropShadowFilter(0,45,0x000000,1,2,2,1,1);
var newImageDataPiece:Bitmap = new Bitmap(); var spriteContainer:Sprite = new Sprite();
var myOrignalImage:Sprite = new Sprite(); var myImage:*; var thePieces:Array = new Array(); var pieceBit:Object = new Object(); var splitAmount:Number = 15; var splitWidth:Number; var splitHeight:Number;
// *** loader var loadBar:LoaderBar = new LoaderBar(); loadBar.x = 10; loadBar.y = 10;
function loadError(e:IOErrorEvent):void { trace("LoadError"); } function loadStart(e:Event) { trace("Load started"); addChild(loadBar); loadBar.LoaderBarExpand.width = 0; } function loadProgress(e:ProgressEvent) { var Percentage:int = Math.round(e.bytesLoaded / e.bytesTotal * 100); loadBar.LoaderBarExpand.width = Percentage; trace(Percentage); }
myLoader.load(new URLRequest("marley.png"));
function loadEnd(e:Event) { removeChild(loadBar); myOrignalImage.addChild(myLoader.content); with (myOrignalImage) { addEventListener(MouseEvent.CLICK, doExplode); mouseEnabled = true; buttonMode = true; x = 350; y = 50; addEventListener(Event.ADDED_TO_STAGE, splitImage); } addChild(myOrignalImage); addChild(spriteContainer); spriteContainer.x = 10; spriteContainer.y = 50; spriteContainer.name = "spriteContainer"; }
function splitImage(e:Event = null) { removeEventListener(Event.ADDED_TO_STAGE, splitImage);
myImage = myLoader.content;
var splitWidth:Number = Math.ceil(myImage.width / splitAmount); var splitHeight:Number = Math.ceil(myImage.height / splitAmount);
var newCopyImage:BitmapData = new BitmapData(myImage.width,myImage.height,true,0x00FFFFFF); newCopyImage.draw(myImage);
for (var i = 0; i < splitAmount; i++) { for (var j = 0; j < splitAmount; j++) { var newImageData:BitmapData = new BitmapData(splitWidth,splitHeight,true,0x00FFFFFF); newImageData.copyPixels(newCopyImage,new Rectangle(i * splitWidth,j * splitHeight,splitWidth,splitHeight), new Point(0,0));
var newImageDataPiece:Bitmap = new Bitmap(newImageData); newImageDataPiece.name = "newImageDataPiece" + i;
I'm not advanced in oop at all so you'll quickly get into stuff I can't answer off the top of my head.
Name your main class Main.
In general when you're starting doing classes or oop, just make everything private. Learn events and event dispatching. If a class/object needs to communicate to parent, dispatch event, referencing parent in oop is against the rules.
OOP is "way" to handle data and program. You'll see that nobody is actually doing totally pure OOP, you use as much OOP as you can until it becomes inefficient.
Use visible to hide/view things that are re-used instead of adding and removing.