View Full Version : NameSpaces - getting functionB to use a var from functionA

Mar 25th, 2007, 09:59 PM
I am trying to devise a scheme where if a user clicks divA and then clicks divB, divB will be able to use a var that was defined in the divA clicked function.

<div id="divA" onClick="selectAttacker()">your unit</div>

<div id="divB" onClick="doCombat()">enemy unit</div>

the user first selects an attacker and then does selects the enemy for the attacker to fire on...

how do I make it so that in the doCombat() function I am able to reference that divA was the unit responsible for causing damage to divB???

Mar 25th, 2007, 10:01 PM
I thought about using namespaces and public functions.. but it isn't working:

YAHOO.game.container = function() {
var fn = function(e, id, param, o) {
// private function -- process arguments here

return {
init : function() {
// blah blah
selectAttacker : function(attackingUnitID, typeOfDmg) {
var attackingUnitID = attackingUnitID;

doCombat: function(targetUnit, typeOfDmg) {


my doCombat() alert() ends up showing the alert dialog box but it is empty... no errors either.

how would you recommend I tackle this problem? I don't have to use namespaces... please let me know how one function can use a var defined in another.

Mar 26th, 2007, 01:55 PM