Having multiple SWFs using flashpunk is causing me problems


(Linck) #1

There is something unexpected happening here. I’m trying to make a Login screen as a separate SWF. So I have my main game, and this main game will load another SWF that is the login screen, then the user will log in and the login screen will vanish completely and the user will return to the main game with his user data. Both the main game and the login screen are made using flashpunk. That is what I was planning.

But I have noticed that when I load the login SWF, if I do for instance a “FP.engine.width = 100” in the main game SWF, both the main game and the loaded SWF screen will be re-scaled to have a width of 100. I was expecting that flashpunk would work completely independent in both SWFs, and the changes I made in the first wouldn’t affect the other.

Interesting is that if I do the command “width = 100” from the SWF that has been loaded, only the width from this loaded swf is affected. That doesn’t make any sense for me.

Have anyone had any experience with multiple loaded SWFs using flash punk here to give me an insight?


(Bora Kasap) #2

That’s about the “root” code. When you call root from a movieclip, it returns root of course. But when you add this movieclip into another moviclip as a child movie clip. Then this root command returns parent’s root, the mostroot. And, the FP has some root calls in it’s engine… So, that’s why you’re getting problems…

Also this one very funny :smiley: https://www.fgl.com/view_thread.php?thread_id=34655

But, you can use it by adding another frame to your swf file from Flash Develop, that could be done with adding some parameters to Project > Properties > Compiler Options > Additional Compiler Options, but i don’t remember what to add there. You can make a search. (it’s something like adding preloader to your swf file, so, you may also search about preloaders to make a login screen)


(Zachary Lewis) #3

Im not even sure if FP.engine.width is an actual thing you can set.

I think that the biggest issue you’re running into is that the FP class has a bunch of static variables in it. Whenever you load the second SWF, it also has an FP class, but since the variables are static, both games share the same values.

What is the problem you are trying to solve? Maybe we can figure out a better solution.


(Linck) #4

I’m using FlashBuilder @AlobarNon. I’m not sure how adding another frame would work. I would put the login screen in one frame and the main game in another, and then give some command to switch frames? I know nothing about it, but I’ll take a look on what I can find.

The topic you linked is indeed really fun =D, but it doesn’t have much to do with my problem does it? (maybe because I didn’t read half the authors post )

@zachwlewis, the FP.engine.width seemed to work fine for me. When I set it to 100, the width of the screen is re-scaled to fit exactly 100 pixels. Also, if it’s a writable variable its probably meant to work. But I was using it just to test this specific issue with SWFs anyway, I don’t have any need to use it for now.

Well, my actual problem is with re-sizing the screen. I’m running the SWFs in a web browser and I listen to when the browser is resized so I resize my game accordingly.

I’m using basically this code to resize:

public function onResize(event:Event=null):void{

	if(FP.stage){
		FP.screen.scaleX = FP.stage.stageWidth / GA.GAME_WIDTH;
		FP.screen.scaleY = FP.stage.stageHeight / GA.GAME_HEIGHT;
		
		if (FP.screen.scaleX < FP.screen.scaleY){
			FP.screen.scaleY = FP.screen.scaleX;
		}
		else{
			FP.screen.scaleX = FP.screen.scaleY;
		}
	}
}

The problem is that both SWF have a listener on them, and they execute almost this same code, and the both execute this code. When the first SWF loads and adds the second as a child, the listener in the first SWF stops working and to let the listener in the second SWF run. Then when I resize the browser window, the second SWF is resized along, but I can see the first swf stuck there with the same size behind the second.

I guess that wouldn’t be a problem if I could hide the first SWF somehow. I would also like to make this first SWF stop all its activities so it doesn’t consume any processing. But I don’t know yet.


(Mike Evmm) #5

I iz very 1337 h4x0rz can r3m0v3 w473rm4rk