Weird behavior when adding multiple sliders

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Yenaphe
Posts: 84
Joined: February 3rd, 2009, 6:30 pm
Location: Paris - France
Contact:

Hi gang,

i'm facing a really weird behavior, and I was wondering what i've been doing wrong.

I'm creating a new adjustement layer, and I want to add 3 slider controls on it and customize them.

This is the code I wrote:

Code: Select all

	var Controler = myObj.ActiveLayers.addSolid([1,1,1], "Controler", myObj.ActiveComp.width, myObj.ActiveComp.height, myObj.ActiveComp.pixelAspect, myObj.ActiveComp.duration);
	Controler.transform.opacity.setValue(0);
	Controler.adjustmentLayer = true;
	
	// adding sliders control to controler
	var SliderOne = Controler.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
	var SliderTwo = Controler.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
	var SliderThree = Controler.property("ADBE Effect Parade").addProperty("ADBE Slider Control");

	SliderOne.property("ADBE Slider Control-0001").setValue(20);
	SliderOne.name = "First Opacity";
	
	SliderTwo.property("ADBE Slider Control-0001").setValue(20);
	SliderTwo.name = "Second Opacity";	
	
	SliderThree.property("ADBE Slider Control-0001").setValue(20);
	SliderThree.name = "Third Opacity";
This code rejects me, and the debugger pops up saying that the line SliderOne.property("ADBE Slider Control-0001").setValue(20); is an undefined object.

But if I write the code this way, it works:

Code: Select all

	var Controler = myObj.ActiveLayers.addSolid([1,1,1], "Controler", myObj.ActiveComp.width, myObj.ActiveComp.height, myObj.ActiveComp.pixelAspect, myObj.ActiveComp.duration);
	Controler.transform.opacity.setValue(0);
	Controler.adjustmentLayer = true;
	
	// adding sliders control to controler
	var SliderOne = Controler.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
	SliderOne.property("ADBE Slider Control-0001").setValue(20);
	SliderOne.name = "First Opacity";

	var SliderTwo = Controler.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
	SliderTwo.property("ADBE Slider Control-0001").setValue(20);
	SliderTwo.name = "Second Opacity";

	var SliderThree = Controler.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
	SliderThree.property("ADBE Slider Control-0001").setValue(20);
	SliderThree.name = "Third Opacity";
But the problem is, if I wanna use my variables later on the code, it will fail, saying that they are an undefined object.
For exemple, try adding after the second code this line and the execution will fail:

Code: Select all

alert(SliderOne.name);
In fact, if i comment the SliderTwo & SliderThree declaration everything works fine, as if I was not allowed to add more than 1 slider control to a layer with this way.

Any hints ?
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

I've experienced similar problem in my scripts, but in most cases it's easy to find a workaround.
In your case, I would write something like this:

Code: Select all

var sldNames = ["First Opacity", "Second Opacity", "Third Opacity"];
var sldValues = [20, 20, 20];

for (var i = 0; i < sldNames.length; i++)
{
	var sldEffect = Controller.Effects.addProperty("ADBE Slider Control");		
	sldEffect.name = sldNames[i];
	sldEffect.property(1).setValue(sldValues[i]);
}
	
var sldOne = Controller.Effects.property(1);
var sldTwo = Controller.Effects.property(2);
var sldThree = Controller.Effects.property(3);

// test
// sldOne.property(1).expression = "random(100)";
Yenaphe
Posts: 84
Joined: February 3rd, 2009, 6:30 pm
Location: Paris - France
Contact:

Thanks Nab, for a minute I was thinking that I might be completely missing the obvious, or becoming crazy.

I did use a workaround as they didn't need to be in the same place, so in my particular case it was easy, but i wanted to understand.

I'm going to report the bug so they can investigate on it.
Post Reply