This one is easy.
First lets go take a look at how this works in the AS3 client. Client-side effects are handled by the engine for the most part, let’s take a look there.
I opened up engine.swf
for the AS3 client in JPEX and searched for filters
in frame 1.
First result is the code we’re looking for, noteably the part which assigns a new flash filter.
// AS3 addPlayer method
function addPlayer(player_ob, targetX, targetY)
{
if(!player_ob.is_in_room)
{
return undefined;
}
var _loc6_ = getRoomMovieClip();
var _loc20_ = getRoomBlockMovieClip();
var _loc4_ = player_ob.player_id;
var _loc8_ = player_ob.nickname;
com.clubpenguin.util.Log.debug("\n============= Adding Player ===============\n",com.clubpenguin.util.Log.ENGINE);
com.clubpenguin.util.Log.debug("Nickname: " + _loc8_,com.clubpenguin.util.Log.ENGINE);
removePlayer(_loc4_);
var _loc12_ = addPlayerDepth(_loc4_);
var _loc13_ = "p" + String(_loc4_);
var _loc2_ = INTERFACE.nicknames_mc.attachMovie("nickname",_loc13_,_loc12_,{_x:targetX,_y:targetY,_visible:false});
_loc2_.name_txt.text = _loc8_;
com.clubpenguin.util.Log.debug("Adding player:",com.clubpenguin.util.Log.ENGINE);
com.clubpenguin.util.Log.debug("\t-local player: " + SHELL.isMyPlayer(_loc4_),com.clubpenguin.util.Log.ENGINE);
if(SHELL.isMyPlayer(_loc4_))
{
var _loc15_ = new flash.filters.DropShadowFilter(0,0,3355443,100,4,4,2000,1);
var _loc10_ = _loc2_.name_txt.filters;
_loc10_.push(_loc15_);
_loc2_.name_txt.filters = _loc10_;
_loc2_.name_txt.textColor = 15658734;
com.clubpenguin.util.Log.debug("-nickname != player_ob.username: " + _loc8_ + " != " + player_ob.username,com.clubpenguin.util.Log.ENGINE);
// I omitted code below which is for AS3 temporary username display feature
}
See how this code is situated in addPlayer
? We have that function in the AS2 engine too, it’s just much smaller…
function addPlayer(player_ob, targetX, targetY)
{
var _loc10_ = getRoomMovieClip();
var _loc14_ = getRoomBlockMovieClip();
var _loc3_ = player_ob.player_id;
var _loc8_ = player_ob.nickname;
The parameters are the same in this case, but in some cases it may be different, pay attention to the AS2 ones, they are important as we a working with the AS2 client. Open up flash pro and make a new flash document.
var ENGINE = _global.getCurrentEngine();
var SHELL = _global.getCurrentShell();
var addPlayer = ENGINE.addPlayer;
ENGINE.addPlayer = function(player_ob, targetX, targetY) {
addPlayer(player_ob, targetX, targetY);
// additional code will go here
}
Press F9 to bring up action pane and start programming! first I made some code to inject our own actionscript onto the end of the engine’s addPlayer
method. This won’t override it, just execute additional code each time it is called.
Now take a look at how the AS3 client adds the filter.
if(SHELL.isMyPlayer(_loc4_))
{
var _loc15_ = new flash.filters.DropShadowFilter(0,0,3355443,100,4,4,2000,1);
var _loc10_ = _loc2_.name_txt.filters;
_loc10_.push(_loc15_);
_loc2_.name_txt.filters = _loc10_;
_loc2_.name_txt.textColor = 15658734;
Finally, apply this code in the context of our custom flash document.
var ENGINE = _global.getCurrentEngine();
var SHELL = _global.getCurrentShell();
var addPlayer = ENGINE.addPlayer;
ENGINE.addPlayer = function(player_ob, targetX, targetY) {
addPlayer(player_ob, targetX, targetY);
if(SHELL.isMyPlayer(player_ob.player_id)) {
var nickname_mc = ENGINE.getNicknameMovieClip(player_ob.player_id);
var filter = new flash.filters.DropShadowFilter(0,0,3355443,100,4,4,2000,1);
var nickname_filters = nickname_mc.name_txt.filters;
nickname_filters.push(filter);
nickname_mc.name_txt.filters = nickname_filters;
nickname_mc.name_txt.textColor = 15658734;
}
}
Now export and save in /play/v2/client
of your media server. Go ahead and open up /play/v2/client/depdencies.json
in a text editor. Add a new entry below engine so it looks like this.
join: [
{
id: 'engine',
title: 'Engine'
},
{
id: 'nicknames',
title: 'Engine'
},
Now save & reload. See SWF & FLA document attached.
Boom.
nicknames.swf (842 Bytes)
nicknames.fla (4.7 KB)