I've even commented out the params.skin = generateSkin() so the params.skin is null. still get the male default. Nor do I see any of the traces I've set up in the ExampleAvatar.as file. I never see the ExampleAvatar class methods called. I've even put a trace in the ExampleAvatar creator. Here is the code as I'm using it now.
Code: Select all
package classes
{
import com.smartfoxserver.openspace.components.flex.OpenSpace;
import com.smartfoxserver.openspace.engine.model.avatar.AvatarCreationParams;
import com.smartfoxserver.openspace.shared.model.other.Position3D;
import flash.display.Loader;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.geom.Point;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
/**
* This class:
* - controls all the avatar-related operations (creation, skin change, etc)
* - controls the avatars library loading
*/
public class AvatarManager
{
private var main:Main // Reference to the main application class
private var openSpace:OpenSpace // Reference to OpenSpace instance
public function AvatarManager(main:Main, openSpace:OpenSpace)
{
this.main = main
this.openSpace = openSpace
}
/**
* Load avatars external library SFW file.
* IMPORTANT: the Application Domain in which the library is loaded must have the current domain as its parent
*
* As this method is called during main application initialization, it enables the login button as soon as the library is loaded.
* On loading completion, the destination application domain is passed to OpenSpace instance.
*/
public function loadAvatarsLibrary():void
{
// Create new application domain
openSpace.avatarAppDomain = new ApplicationDomain(ApplicationDomain.currentDomain)
var loader:Loader = new Loader()
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCompletion, false, 0, true)
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoadError, false, 0, true)
var request:URLRequest = new URLRequest("libraries/avatar/AvatarsContainer.swf")
var context:LoaderContext = new LoaderContext(false, openSpace.avatarAppDomain)
loader.load(request, context)
}
/**
* Create the player's avatar.
*/
public function createPlayerAvatar(centeringCoords:Point, direction:int):void
{
var params:AvatarCreationParams = new AvatarCreationParams()
params.type = "example"
// params.skin = generateSkin()
params.centerViewport = true
if (centeringCoords != null)
{
params.px = centeringCoords.x
params.py = centeringCoords.y
params.direction = direction
}
try {
openSpace.createMyAvatar(params)
}
catch (e:Error) {
main.logTrace("AVATAR CREATION ERROR: " + e.message)
}
main.logTrace("Avatars created")
}
/**
* Create the player's avatar skin.
*/
public function changePlayerAvatarSkin():void
{
openSpace.setMyAvatarSkin(generateSkin())
}
/**
* Teleport the player's avatar.
*/
public function teleportPlayerAvatar():void
{
openSpace.teleportMyAvatar(new Position3D(main.ns_px.value, main.ns_py.value))
}
/**
* Move the player's avatar.
*/
public function movePlayerAvatar():void
{
openSpace.moveMyAvatar(new Position3D(main.ns_px.value, main.ns_py.value))
}
/**
* Stop the player's avatar during its movement.
*/
public function stopPlayerAvatar():void
{
openSpace.stopMyAvatar()
}
/**
* Center viewport on player's avatar coordinate.
*/
public function centerPlayerAvatar():void
{
openSpace.centerViewOnMyAvatar()
}
/**
* Set the player's avatar animation time (speed).
*/
public function setPlayerAvatarAnimTime():void
{
openSpace.setMyAvatarAnimationTime(main.ns_animTime.value)
}
//-----------------------------
// PRIVATE METHODS
//-----------------------------
private function onLoadCompletion(e:Event):void
{
main.logTrace("Avatars external library loaded")
// Enable login button
main.bt_login.enabled = true
}
private function onLoadError(e:IOErrorEvent):void
{
main.logTrace(e.text)
}
private function generateSkin():Object
{
main.logTrace("Avatars generateSkin() called.")
var isMale:Boolean = main.rb_male.selected
var skin:Object = {}
skin.sex = isMale ? "m" : "f"
skin.race = "european"
skin.hair = main.cb_hair.selected ? (isMale ? "hair1" : "hair2") : ""
skin.bust = main.cb_bust.selected ? (isMale ? "shirt1" : "shirt2") : ""
skin.legs = main.cb_legs.selected ? (isMale ? "jeans1" : "jeans2") : ""
return skin
}
}
}
I do note that when I change the generateSkin function so it is set to male the avatar does change.
Still, Im much more interested in why the ExampleAvatar methods don't seem to being called. Yes, I am looking in the Flash Builder debug console window.