Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-07-2010, 09:24 PM   #1
jagguy
Senior Member
 
Join Date: Aug 2006
Posts: 275
Default [AS3] cant split the stage

I have 3 images to display in actionscript 3 project.

The stage is 940 wide and 480 height.

The stage is split in 2 where 1 sprite is on the left 740X480 and the right side has another sprite 200X480.
I place a 3rd image on the left sprite when all the images are loaded .

I uploaded a demo here and just dismiss all if get an error.


MY QUESTION- I want to load 2 images (2 large sprites 'Cave maths' and right side 'cave math'). when both are loaded display the white playgame button.

I cant do this with this code. Turning the button to visible when all is loaded isnt working

http://www.mymrt.net/cm1/cm1.html //////// this project has the button visible from load but I dont want this

Code:
myintro=new ClassIntro();
	myintro.addEventListener ("introClicked",intro_Handler);
	addChild(myintro);
		
myRightside=new ClassRightside();
addChild(myRightside);

///////////////////
///loading the button
private function imageLoaded(event:Event):void
        {
 var image:Bitmap = new Bitmap(event.target.content.bitmapData);
 addChild(spButton); 
 spButton.addChild(image);	
		 
		 
	//	 IntroCanvas.addChild(spButton);
	spButton.visible=false;
		 


public function btnPlay():void
		{
						
			spButton.addEventListener(MouseEvent.CLICK ,doSomething); //image wont take button clicks but sprite will
			
spButton.x = 240;
spButton.y = 350;
trace("btnplay ok");
trace("kk"+spButton);
		
spButton.visible=true; ////////////doesnt WORK !!!!!!!!!!!
		}
jagguy is offline   Reply With Quote
Old 11-07-2010, 10:39 PM   #2
jdinz
Member
 
Join Date: Nov 2010
Location: New Zealand
Posts: 93
Default

Nice game you've got going there!

Ok, sooo, you're post is a little confusing so I hope I understood your correctly.

1. I've tidied up your code... messy code = a messy mind.
2. It seems like a timing issue, if you're imageLoaded() function runs AFTER your btnPlay() function it's gonna end up visible = false.
3. I don't understand why you have used event.target.content.bitmapData, when you could just use event.target.content. I assume that you are loading a file (e.g .jpg)... not sure why you would load raw bitmap data for this.
4. Also, it looks like you're going about this a really weird way - you might want to consider re-organizing you're method...

I've added a simple if statement that checks which .visible method is running first..

ActionScript Code:
var spButton:Sprite = new Sprite(); var imageIsLoaded:Boolean = false; /////////////////// ///loading the button private function imageLoaded(event:Event):void {     var image:Bitmap = event.target.content;     addChild(spButton);     spButton.addChild(image);        //IntroCanvas.addChild(spButton);     spButton.visible=false;     imageIsLoaded = true;          } public function btnPlay():void {                             spButton.addEventListener(MouseEvent.CLICK, doSomething); //image wont take button clicks but sprite will     spButton.x = 240;     spButton.y = 350;         if(imageIsLoaded) {         spButton.visible=true;     } else {         trace("Chill out bro, your spButton.visible = false; hasn't even run yet");     } }

I organized you're script a little and added a new function that represents a good time to change the .visible state of your spButton:

ActionScript Code:
var spButton:Sprite = new Sprite(); var imageIsLoaded:Boolean = false; function imageLoaded(event:Event):void {     var image:Bitmap = event.target.content;     imageIsLoaded = true;     createBtnPlay(image);          } function createBtnPlay(image:Bitmap):void {                             spButton.addEventListener(MouseEvent.CLICK, doSomething);     spButton.x = 240;     spButton.y = 350;     spButton.addChild(image);     spButton.visible=false;     addChild(spButton);     } function allImagesAreReadyAndItsTimeToShowButton():void {     if(imageIsLoaded) {         spButton.visible=true;     } else {         trace("Your createBtnPlay() function still hasn't run! What is your script up to...");     } }
jdinz is offline   Reply With Quote
Old 11-07-2010, 11:59 PM   #3
jagguy
Senior Member
 
Join Date: Aug 2006
Posts: 275
Default

I am new to AS3 so I am bound to make make some sloppy errors and thanks for pointing these out. I am loading external images so your way is the correct way?

Now what you havent seen is the event frame event which counts all images loaded (about 300). once this is done then the option to start the game appears.

I have the solution-
Also I load the buton image and then make it visible=false.
I then load the intro screen it sits in.
I then get the signal all is loaded and turn the button on.
it works as the load order is illogical in AS3?

Last edited by jagguy; 11-08-2010 at 12:02 AM.
jagguy is offline   Reply With Quote
Old 11-08-2010, 12:26 AM   #4
jdinz
Member
 
Join Date: Nov 2010
Location: New Zealand
Posts: 93
Default

Yea you've got the right idea, except that I'm assuming you mean "it works as the load order is LOGICAL in AS3?"
jdinz is offline   Reply With Quote
Old 11-08-2010, 12:47 AM   #5
jagguy
Senior Member
 
Join Date: Aug 2006
Posts: 275
Default

no the load order is not logical.
What I think happens is that if you make an object invisible it swaps position in the display list with objects above it.
so you load the image you want displayed on top first, make it invisible, load the other image and then make the object visible again
jagguy is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:01 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.