Loading different assets for desktop and mobile

This function should do what I need:

public static function getBrowserType(): String {
	var browserType: String = "Undefined";
	
	var browserAgent : String = Browser.navigator.userAgent;
	
	if (browserAgent != null) {
		
		if	(	browserAgent.indexOf("Android") >= 0
			||	browserAgent.indexOf("BlackBerry") >= 0
			||	browserAgent.indexOf("iPhone") >= 0
			||	browserAgent.indexOf("iPad") >= 0
			||	browserAgent.indexOf("iPod") >= 0
			||	browserAgent.indexOf("Opera Mini") >= 0
			||	browserAgent.indexOf("IEMobile") >= 0
			) {
			browserType = "MOBILE";
		}
		else {
			browserType = "DESKTOP";
		}
	}
	
	return browserType;
}

For what concerns the different assets for mobile or desktop I think an example will better explain what I need:

I have several assets folders

assets/defaultGFX
assets/mobileGFX
assets/desktopGFX
assets/defaultSFX
assets/mobileSFX
assets/desktopSFX

Normally in my project.xml I should add

<assets path="..." />

for each folder, but in this case I’d like to add

assets/defaultGFX
assets/defaultSFX

only, and load

assets/mobileGFX
assets/mobileSFX

if I detect a mobile device, or

assets/desktopGFX
assets/desktopSFX

in all other situations.
In this example I have splitted the mobile and desktop assets completely in different folders, it would be the better solution to keep things clear, but I would accept to mix the assets in the same folder too, if I had the possibility to load specific files from it.

I have to consider Flash target too, because it is the main target for development, and it needs to embed all assets statically, I don’t care if it embeds both mobile and desktop assets, even if it would be correct embedding the latter ones only.

1 Like