• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AS3 loading dynamic bitmap data on a layer of a child MC

Explorer ,
Jul 12, 2024 Jul 12, 2024

Copy link to clipboard

Copied

I think the solution is simple but I couldn't figure it out over sleeping on it. I feel stupid, but have no idea what my mistake is since I recieved no error. I think it's syntax based, but again no error throws me into a loop.

Trying to make an old school Concentration game with trilons based on the show from the 50s-70s (ala Hugh Downs, Jack Narz). So step by step, I have the rebus loaded and cut into pieces. I'm using a three layered movie clip (tr) to represent the trilon (NOTE: all instances of tr are placed on stage via animate with proper names). I've been able to to load the pictures into tr, but struggling with getting the sprite to load on the puzzle side of the trilon (rSide). When executing the function testRotate, tr plays, but the rebus bitmap/sprite doesn't show. I tried a few different methods (I think 6 or 7), the last three are commented in the code below under the placePuzzle function. I totally thought that addChildAt would have done the trick since this bitmap is dynamically generated (that was my sleeping revelation), but no avail. Yet, I recieved no error when debugging even in strict mode. Any help on where I made my mistake and my error in logic would be appreciated.

var loader: Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingDone);
var request: URLRequest = new URLRequest("puz1.png");
loader.load(request);


var trs: Array = [tr1, tr6, tr11, tr16, tr21, tr26, tr2, tr7, tr12, tr17, tr22, tr27, tr3, tr8, tr13, tr18, tr23, tr28, tr4, tr9, tr14, tr19, tr24, tr29, tr5, tr10, tr15, tr20, tr25, tr30];
var puzPieces: Array = new Array();

stage.addEventListener(KeyboardEvent.KEY_DOWN, testRotate);
function testRotate(event: KeyboardEvent): void {
	if (event.keyCode == 39) {
		for each(var objA: MovieClip in trs) {
			objA.play();
		}
	}
}
function loadingDone(event: Event): void {
	var image: Bitmap = Bitmap(event.target.loader.content);
	var pieceWidth: Number = 200;
	var pieceHeight: Number = 100;

	for (var x: uint = 0; x < 5; x++) {
		for (var y: uint = 0; y < 6; y++) {

			// create new piece as bitmap
			var newPuzzlePieceBitmap: Bitmap = new Bitmap(new BitmapData(pieceWidth, pieceHeight));
			newPuzzlePieceBitmap.bitmapData.copyPixels(image.bitmapData, new Rectangle(x * pieceWidth, y * pieceHeight, pieceWidth, pieceHeight), new Point(0, 0));

			// create the new sprite--add bitmap data
			var newPuzzlePiece: Sprite = new Sprite();
			newPuzzlePiece.addChild(newPuzzlePieceBitmap);
			puzPieces.push(newPuzzlePiece);
			trace(puzPieces);
			placePuzzle();
		}
	}
}
var sB: int = 0;
function placePuzzle(): void {
	if (sB <= 29) {
		//trs[sB].addChild(puzPieces[sB]);
		//trs[sB].rSide.container.addChild(puzPieces[sB]);
		//trs[sB].rSide.addChildAt(puzPieces[sB],0);
		trs[sB].rSide.addChild(puzPieces[sB]);
		++sB;
	}
}

 

TOPICS
ActionScript

Views

59

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jul 15, 2024 Jul 15, 2024

Since I didn't get a response I decided to fix it all within Animate by instead of having the three movie clips in one trilon movieClip, I just made three separate layers on the main stage with each part of the trilon on a layer.

Votes

Translate

Translate
Explorer ,
Jul 15, 2024 Jul 15, 2024

Copy link to clipboard

Copied

LATEST

Since I didn't get a response I decided to fix it all within Animate by instead of having the three movie clips in one trilon movieClip, I just made three separate layers on the main stage with each part of the trilon on a layer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines