setText inside cloned clips

this is the situation
I have a text field inside a clip
I want to clone the clip and change text inside every clone

issue n1: once cloned you cannot change text inside the cloned clip
issue n2: I tried the workaround to change text in base clip before cloning but the clone still retain the original text (text base clip had before changing)!

textInClones.wick (1.6 KB)

btw
I can retrieve the text value with
stringInsideTextField=tx.json[1].content //tx is text field name

if I try to set it at runtime it does not work but strangely enough it will change the text string when I stop the execution
tx.json[1].content =“some other string” //wont work at runtime. works after stop ?!?

I dont have my pc, but im pretty sure that i have done it in the past.

The limitation is that you cant clone and update the text on the same frame.

To setText something inside of an object, I would usually try to find out if it’s a clone by using if(this.isClone){ /*Plug in code here*/ } in its default, then set the text inside if it is

Example.wick (1.6 KB)

I feel like you should be able to spawn a clone and change its inside objects (if u have the cloned defined as a variable)

2 Likes

Another thing that you could try… not sure if it would work is…

Try to change te text to the initial object before cloning.

You should use “this” when you are inside a clip.
Here is an example… you have to change their text a frame after you clone them.
textInClones.wick (1.7 KB)

ty all for your reply

@Jovanny
apparently changing text to base clip and then cloning does not work
I see your project working but I dont get how is that if I write; (textCont2 is the cloned clip)
textCont2.y+=100; //ok
textCont.tx.setText(“other text”);//error

thankyou for pointing out that. this is quite a big issue in my opinion

also it should be possible to change base clip text and then clone it but probably it’s the same bug

I think, what @Hamzah_Alani sent you is a better approach… He is doing the setText at the clone default code… At that point the clone is ready to accept the setText update. Take a look…

It is, but at the same time we should understand this limitation… It will happens everytime… not only in this case… when you clone a clip… the first frame (the one that you used the clip.clone() ) will run the base constructor with only the main attributes that the wick.clip has. That is why clip.y works. At that point, your clone haven’t built your custom prototype things so your clip.tx doesn’t exist yet. After a frame, your clip.tx exists, and it is ready for being used.

@Hamzah_Alani solution works because at that point (at clone default) the custom prototype things are built already.

yes hamzah solution is good too
In the attached project I added a variable to the clone to customize the strings for every clone
It’s likely that the control could be done directly on the presence of the string to be set thus skipping the if is clone.

textInClones2.wick (1.6 KB)

1 Like

Previously I had a scenario where I could assign text to one clip, and have the clone basically ‘inherit’ the text of the original clip…but now I’m thinking that might’ve been a weird fluke of some kind, because I can’t seem to recreate it. At any rate, Hamzah’s solution is really good so I probably shouldn’t even mention this…I guess I’m just weirded out that I got the clone inheriting text thing to work even once.

Actually, I think I figured it out why it worked for me before…and the reason is really weird. So after changing the fontFamily property of the original clip’s text…this apparently makes it possible for clones to inherit the text of the original clip. Does this work for anyone else?
cloneText.wick (1.7 KB)

1 Like

Yup, your solution works by changing the text before cloning…
So it seems that changing the font family force the editor to change the font with the content on that same frame. Otherwise would not work. It should.

You should not be able to do it after cloning, because the what I tried to explain above. They should fix all of this anyway… .it is a limitation for sure.

another solution that works is to set clone clip on update programmatically

myClonedClip.onEvent(‘update’, function () {
// set text once
// do something else
}