PDA

View Full Version : getter/setter trouble


Kuma
11-20-2004, 05:06 PM
Hi,

I'm having a little trouble with setting a variable via a getter and setter.

Basically I want to store a reference to my current selection, so that I can reset it to a previous state later in the code

But for some reason my lastSelection is always returning undefined

Could someone explain what is going on and how I could fix it please?


Thanks.

var currSelection;
var lastSelection;

function getSelectionData(){
var selected = fl.getDocumentDOM().selection[0];
if(selected!=undefined && (fl.getDocumentDOM().selection.length == 1)){
if(getLastSelection() != undefined){
resetSymbol();
}
// store reference to current selection
setCurrSelection(selected);
setLastSelection(selected);
}
// I have omitted the rest of the code
}
//
// ------------------------------------------------
// GETTERS AND SETTERS
// ------------------------------------------------
//
function setLastSelection(val){
lastSelection = val;
fl.trace("setLastSelection("+val+")")
}
//
function getLastSelection(){
fl.trace("getLastSelection(): "+lastSelection)
return lastSelection;
}
//
// ------------------------------------------------
//
function setCurrSelection(val){
currSelection = val;
}
//
function getCurrSelection(){
return currSelection;
}

Kuma
11-21-2004, 02:15 AM
Hi,
I have discovered something, which seems to be causing the issue.

I am calling a function in my JSFL file from my WindowSWF on a setInterval and it appears that the JSFL is being reloaded(?) with each event. In effect it isn't storing my references because they are being wiped.

in my WindowSWF Fla

var nSelectionInt = setInterval(this, "getSelection", 300);


in my JSFL

// at the top I placed a
fl.trace("reloaded")
// above the existing:
var currSelection;
var lastSelection;


and it seems to trace

reloaded
reloaded
reloaded
// and so on



So, my problem doesn't actually appear to be the getter/setter anymore.
It seems that the setInterval is the culprit. However, this now seems to leave me with a new issue.

How can I perform a setInterval, with out the JSFl reloading?
or
How can I store a reference to my current selection? (I imagine I'll have to pass currentFrame, currentLayer, elements* data back and forth between the SWF and the JSFL)

(*if the last option is what I have to do, how can I find out the elements index?)


Thanks

hangalot
11-22-2004, 08:53 AM
yes, jsfl does not store the reference, with each call it gets reloaded. u can pass the strings identifying the selection around, but i would imagine it could get nasty. there are some other issues with setinterval from a windowswf and the selection object as well,
read this:
http://johan.plasmapudding.com/index.php?id=208