listening to an object's attribute change from within a JS object?
hello max experts,
Like the title says, i was wondering how i could listen permanently for an object's attribute change, let's say its background color, and get a message out whenever the changing occurs (like one would do in a patch with a normal [getattr bgcolor @listen1] object
any thoughts?
thanks guys!
Hi, not possible as far as I'm aware. Any changes in a patch have to be routed into a js object via an inlet. I'd love this to be wrong, so happy if anyone else knows more about this... I've always wondered if something like this is available via the pattr system, it never figured out a way...
thanks Lee, well i guess i'd have to stick to the [getattr bgcolor @listen1] object... It's easy with normal objects, but i'm struggling with bpatchers...
do you have any idea how to get the presentation_rect attribute of a bpatcher (loaded with a patcher) from a normal max object? or from within JS?
In a JS object i can query the attribute of an EMPTY bpatcher easily:
function bang ()
{
outlet (0, this.patcher.getnamed("thebpatcher").getattr("presentation_rect"))
}
it returns the a b c d coordinates, BUT if i load a patcher in it, it just returns "js object -123213...."
i attached an example just in case, the bpatcher is empty, banging gives the coordinates, but then after loading the "patchertoembed" patch, banging does not return the coordinates anymore...
where am i missing something? There must be some mistake somewhere... Maybe i'll post this question as a new topic...
thanks again!
bit of a funny one this:
if you use this.patcher.getnamed("thebpatcher").rect, it will give you the patcher co-ordinates if you are in patching mode, and presentation co-ords if in
presentation mode... not sure if there's any other way of getting the info without having to first switch to the appropriate mode and then get the co-ords
oooooooh indeed... Thank you so much!I think that solved my problem...
@LEE Any idea how to output the values for rect in float format instead of int?
Indeed for the float values you need the presentation_rect attribute. I managed to get it for a bpatcher like this:
if (obj.maxclass == "patcher" && obj.getattr("presentation_rect") == null) { // bpatchers return null for presentation_rect, as opposed to normal patchers
var l = new MaxobjListener(obj, "presentation_rect", null)
var r = l.getvalue()
}
Mattijs,
Wow. It's been so long now that, when I saw the notification email for this thread, I couldn't remember what I had posted here or why. But now I can recall that, as a result of getting stuck on this problem, I left the big project I was working on at the time sitting on a shelf and gathering dust for the last three and a half years or so.
However, now that I finally have a solution for this, I think I may finally be able to go back and pick it up where I left off. I just hope it hasn't been so long now that I can't remember what I was doing or how it all works haha!
In any case, Thank you! I sincerely appreciate your response and the info. And even though it took over 3 years to receive this solution, it truly is better late than never. :)