Jump to content


Photo

effectList


  • Please log in to reply
5 replies to this topic

#1 abeall

abeall

    FireworksNut

  • Administrators
  • PipPipPipPipPipPip
  • 523 posts

Posted 07 September 2006 - 10:20 PM

I'm becoming an expert at crashing FW. I've been spending a surprising amount of time attempting to get "Disable All Effects"/"Enable All Effects" commands working(in response to the same wish in the wish forum). While I got something working in a few minutes, I realized soon that something wasn't right... without going into details, this is where I stand:

var f = { EffectIsVisible:true, EffectMoaID:"{e4c0f4bc-c0a3-4cb3-b3513822027e4d9f}", MB_filter_preview_tile_size:"-1 -1", add_noise_amount:26, add_noise_use_color:false, category:"Noise", name:"Add Noise..." };

fw.selection[0].effectList = {category:"Untitled", effects:[f], name:"Untitled" };
That works. I create an Object with the needed filter params(for Add Noise), and use it by assigning it in the effectList.effects.

However:
var eff = fw.selection[0].effectList.effects[0];
var f = new Object();
for(var i in eff){
	f[i] = eff[i];
}

fw.selection[0].effectList = {category:"Untitled", effects:[f], name:"Untitled" };

The above seems to work at first. I take the element I applied the earlier Add Noise command to, and run this command. Nothing changes, naturally, because I'm not changing the Effect properties, just copying it and re-assigning. But as soon as I try to edit the Effect in the Property Inspector, FW promptly quits. I actually tried accessing the effectList.effects Array directly at first, and got identical crash symptoms. I also tried using applyEffects() and got the same. Some effects didn't cause a crash, some did. Add Noise was one that did.

So after some poking around, I tried instantiating new Effect instead of new Object. And, it stopped crashing! However, there was still a serious(different) problem. The new Effect constructor seemed to make a Bevel, and some properties of the new Effect seemed uneditable. This meant I was unable to fully copy old effects. Try this code:
var eff = fw.selection[0].effectList.effects[0];
var f = new Effect();
for(var i in eff){
	f[i] = eff[i];
}

fw.selection[0].effectList = {category:"Untitled", effects:[f], name:"Untitled" };
Try it on an object which has only an Inner Shadow with all it's properties changed significantly from the defaults. Notice that after the command, some Inner Shadow properties revert to defaults(7 offset, 4 blur).

So I'm stuck, and it's 2am, I need to go to bed. :) Obviously all I'm trying to do is edit the existing effects on an element. First I tried directly accessing effectList.effects[i].Effect properties, but they didn't seem to want to change. The docs don't mention them being read-only, but unless I'm going crazy EffectIsVisible was not being set.
var effs = fw.selection[0].effectList.effects;
for(var i in effs){
	alert(effs[i].EffectIsVisible);
	effs[i].EffectIsVisible = !effs[i].EffectIsVisible;
	alert(effs[i].EffectIsVisible);
}

Any advice on what's going on here or what my approach with editing effects should be would be greatly appreciated!
Thanks

#2 Hiroshi

Hiroshi

    Fireworker

  • Members
  • PipPipPip
  • 46 posts

Posted 08 September 2006 - 03:20 PM

Try skipping "javascriptString". i.e.

var eff = fw.selection[0].effectList.effects[0];
var f = new Object();
for(var i in eff){
	if (i!="javascriptString")
		f[i] = eff[i];
}

I don't think FW likes anyone else touching that one. ;)

It's probably getting confused because javascriptString is different from what it should be. I'm just guessing here, so don't quote me on that.

As for not being able to directly modify effect propeties, that's probably FOL (fact of life). I think other objects behave the same way, but I can't remember which ones.

Hope that helps.

#3 abeall

abeall

    FireworksNut

  • Administrators
  • PipPipPipPipPipPip
  • 523 posts

Posted 10 September 2006 - 12:49 PM

Right on, Hiroshi -- you are a good guesser. ;) It all works now. I was curious about that javascriptString property... what exactly is it for? I couldn't find any documentation on it, but I'll be sure to leave it alone in the future!

Thanks.

[EDIT] Tada:
http://www.fireworks...p?showtopic=169
Thanks again for the help!

#4 Hiroshi

Hiroshi

    Fireworker

  • Members
  • PipPipPip
  • 46 posts

Posted 10 September 2006 - 08:12 PM

"javascriptString" is like calling "toString()" in other languages like AS3.0 etc. It's basically a string representation of the object you're referencing. I'm almost certain that you can use this on every object in FW.

Glad I could help. :)

#5 senocular

senocular

    Fireworks Extender

  • Administrators
  • PipPipPipPipPip
  • 150 posts
  • Location:San Francisco, CA (USA)

Posted 11 September 2006 - 07:57 AM

There's also the javascript .toSource() which is good for getting a string rep. of an object as well.

I too have had problems with javascriptString and remember in the past having to do exactly what Hiroshi suggested.

#6 lungdisc

lungdisc

    FireworksCommander

  • Members
  • Pip
  • 7 posts

Posted 02 December 2011 - 10:51 AM

"javascriptString" is like calling "toString()" in other languages like AS3.0 etc. It's basically a string representation of the object you're referencing. I'm almost certain that you can use this on every object in FW.

Glad I could help. :)


It's not just the javascriptString value that crashes fireworks. If you want to output what's inside the dom it will also crash on these properties (backgroundUrl, mapType, lastExportDirectory etc).

In order to bypass the crashing you need to wrap your code with try/catch.

Here's a function I use to dump the contents of an object: http://www.fireworks...showtopic=16769