Page 1 of 1
createMyAvatar & params.skin
Posted: 03 Aug 2011, 16:51
by JimDaniel
I've run into an interesting problem with the createMyAvatar method. No mater what I set the skin values to I always start out with the avatar without any skins and facing se. Any idea what I forgot to do?
AvatarManager
Code: Select all
public function createPlayerAvatar(centeringCoords:Point, direction:int):void
{
var params:AvatarCreationParams = new AvatarCreationParams()
params.type = "example"
params.skin = generateSkin();
params.name = "JIM";
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.dTrace("AVATAR CREATION ERROR: " + e.message)
}
}
.
.
.
private function onLoadCompletion(e:Event):void
{
main.dTrace("Avatars external library loaded");
createPlayerAvatar(null, 6);
}
.
.
.
private function generateSkin():Object
{
var isMale:Boolean = false;
var skin:Object = {};
skin.sex = "f";
skin.race = "european";
skin.hair = "hair2";
skin.bust = "shirt2";
skin.legs = "jeans2";
return skin;
}
Posted: 11 Aug 2011, 11:42
by Bax
You have to implement the Avatar.init() method. In this method you have to set the avatar appearance.
Avatar.init()
Posted: 11 Aug 2011, 14:38
by JimDaniel
I'm assuming that the Avatar.init() you are talking about is the same as the init() in ExampleAvatar.as of the os1Example code. As far as I can tell this method is not called when the avatar is created. I've un-commented out all of the trace in ExampleAvatar.as & changes the the following line in the exampleAvatar.init() method
to
with no effect. Before you ask I I'm running these tests in os1Example and I'm doing a project clean to insure everything is rebuilt/compiled before running.
Posted: 11 Aug 2011, 14:46
by Bax
Did you clean the browser's cache too?
Also, in Example 1 when the avatar is created, the male sex is passed in the skin object, so even if you change the defaultSkin variable, you will still get a male avatar.
Yes, cleaning cash too.
Posted: 11 Aug 2011, 16:26
by JimDaniel
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.
Posted: 12 Aug 2011, 09:29
by Bax
Just to make sure... are you re-exporting the AvatarsContainer.swf file after you make the modifications to the ExampleAvatar.as file?
Posted: 13 Aug 2011, 15:21
by JimDaniel
Yes I do republish the AvatarsContainer.SWF file. I've even deleted the AvatarsContainer.SWF file to be sure it is being replaced. I still do not see the Avatar.as file trace statements when I create the player avatar.
Posted: 15 Aug 2011, 07:26
by Bax
Not sure what is wrong on your side but I just tested this again using Example 1 for SFS2X and everything is fine.
I entered a trace statement in the init method of the ExampleAvatar class, re-exported the AvatarsContainer.swf.
When I run the example the statement it is traced in the Flex console as expected.