Skip to content

Frames and links

Updated

Three small components finish a piece of media. A Frame draws a picture frame around an image, a video or a document. An Attribution records who made something and where it came from, so a gallery can credit its artists. A Link turns a button into a hyperlink that opens a web page. None of them costs anything per frame, and each is a single setProps away from a script. This page explains all three and shows how scripts build hover highlights, credit walls and tracked links with them.

  • Image surfaces. A Frame wraps the plane an image, video or document draws on. See Images.
  • Selection events. The hover and click examples rely on a Selectable and a Signal Emitter on the framed entity. See Input and interaction.
  • UI buttons. A Link lives on UI entities. See UI.

A Frame (comp-frame, script class FrameComponent) draws a flat border just outside the edge of its entity’s surface, so it never covers the picture. It follows the surface’s size, including when intrinsic sizing or a new PDF page changes it.

It works on Image, KTX2, SVG, GIF, Lottie, Video and PDF entities. A surface with no flat extent, such as a 360 sphere, has no frame; the frame comes back if the surface becomes planar again.

Prop Type Default Description
src string none A texture for the frame, such as wood grain. Absent, a flat colour.
color string '#ffffff' The frame colour, or the tint multiplied onto src.
thickness number 0.05 Border width in metres, outward from the surface’s edge.
gap number 0 Space between the surface’s edge and the frame, in metres. The scene shows through it, like a passe-partout cut-out.
offset number 0.001 Distance in front of the surface, so the frame does not flicker against it.
opacity number 1 Overall opacity. Below 1 the frame is drawn transparent.
side 'double' | 'front' | 'back' 'double' Which faces are drawn.
repeat number 1 How many times src tiles around the frame.

An SVG surface is a 1 × 1 box scaled by its entity, so its frame is sized in the same units and scales with it.

An Attribution (comp-attribution, script class AttributionComponent) is information, not a visual: it stores the credit for a work so scripts, and the people who browse the scene, can find it. Images, documents, text and many other entities accept it.

Prop Type Default Description
title string '' The work’s title.
author string '' Who made it.
link string none Where it comes from: its page, source or licence.

Each value must be a string; setProps throws a TypeError otherwise.

A Link (comp-link, script class LinkComponent) turns its entity into a hyperlink: pressing it opens url, in a new tab by default. It is offered on UI Button, UI Label, UI Image, UI List Item and UI Avatar entities.

Prop Type Default Description
url string none The page to open. Empty, the link does nothing.
target '_blank' | '_self' '_blank' _blank opens a new tab; _self replaces the current page, leaving the experience.
Member What it is
open() Open the link from a script. Does nothing when the component is disabled or url is empty.
url The destination, or undefined when unset. Read-only; change it with setProps.
target Where it opens. Read-only.
  • It opens when the entity is pressed, and stops the press there, so entities behind it are not pressed too.
  • It works in play only. In the editor, pressing the entity selects it as usual.
  • It refuses javascript:, vbscript: and data: URLs, and anything that is not a valid URL.
  • Popup blockers. A browser may block a new tab that does not directly follow a click or key press. Call open() from an input handler, not from a timer.
Event EventType Data When
Link::open EventType.Link.Open { url } The link opened its URL.

For an entity that cannot carry a Link, such as a framed image, WebBrowser.navigateToURL(url) opens a URL in a new tab from any script. It allows http:, https:, mailto: and tel: addresses.

A framed picture whose frame turns gold and thickens while the pointer is over it. The Behavior entity is a child of an Image entity that has a Frame, a Selectable and a Signal Emitter whose signal is artwork.

HoverFrame.jx
#pragma lifecycle(startup)
const NORMAL = { color: '#1f2937', thickness: 0.04 };
const HOVER = { color: '#d4a017', thickness: 0.07 };
function startup() {
const frame = self.parent.getComponent(FrameComponent);
frame.setProps(NORMAL);
on('artwork', (event) => {
if (event.eventType === EventType.Selectable.Hover) frame.setProps(HOVER);
if (event.eventType === EventType.Selectable.Leave) frame.setProps(NORMAL);
});
}
  • The Selectable sends Selectable::hover when the pointer arrives and Selectable::leave when it goes. The Signal Emitter forwards both on artwork.
  • setProps takes several props at once, so each state is one object.
  • Changing a frame is cheap: it rebuilds an 8-triangle mesh.

A sign that lists the title and author of every artwork in a gallery. The scene has a group entity named Gallery whose child entities carry Attributions, and a Text entity named Credits.

CreditsWall.jx
#pragma lifecycle(startup)
function startup() {
const gallery = findEntity('Gallery');
const lines = [];
for (const child of gallery.children) {
if (!isEntity(child)) continue;
const credit = child.getComponent(AttributionComponent);
if (!credit || !credit.props.title) continue;
const author = credit.props.author || 'Unknown artist';
lines.push(`${credit.props.title} by ${author}`);
}
const credits = findEntity('Credits').getComponent(TextComponent);
credits.setProps({
text: lines.length ? lines.join('\n') : 'No credits yet',
fontSize: 0.08,
maxWidth: 2,
textAlign: 'left',
anchorX: 'left',
anchorY: 'top',
});
}
  • gallery.children holds the gallery’s direct children. isEntity skips anything that is not an entity, such as a plain object added by a script.
  • getComponent returns undefined when the entity has no Attribution, so the if skips uncredited children.
  • The list is built once, in startup, and set in one setProps call.

A UI button with a Link whose address records which room the visitor came from, and a counter of how many times it opened. Pressing T opens it too. The scene has a UI Button named Tickets Button with a Link and a Signal Emitter whose signal is tickets.

TicketsLink.jx
#pragma lifecycle(startup, update)
const BASE = 'https://example.com/tickets';
const ROOM = 'lobby';
let link;
let opened = 0;
function startup() {
link = findEntity('Tickets Button').getComponent(LinkComponent);
link.setProps({ url: `${BASE}?from=${ROOM}`, target: '_blank' });
on('tickets', (event) => {
if (event.eventType !== EventType.Link.Open) return;
opened++;
log(`Tickets opened ${opened} time(s): ${event.data.url}`);
});
}
function update() {
if (Input.keyboard.isKeyReleased(Key.T)) link.open();
}
  • setProps({ url }) sets the address at start, so one scene can send different rooms to different pages.
  • Link::open reports every opening, whether from a press on the button or from open().
  • open() runs from a key press, which browsers accept as a user gesture.
  • target: '_blank' keeps the experience open in its own tab.

Clicking a framed picture opens the page its Attribution links to. The Behavior entity is a child of an Image entity with an Attribution, a Selectable and a Signal Emitter whose signal is artwork.

OpenSource.jx
#pragma lifecycle(startup)
function startup() {
const artwork = self.parent;
const credit = artwork.getComponent(AttributionComponent);
on('artwork', (event) => {
if (event.eventType !== EventType.Selectable.Select) return;
findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
if (!credit || !credit.props.link) {
log('No source link for this artwork');
return;
}
WebBrowser.navigateToURL(credit.props.link);
});
}
  • A Link is offered only on UI entities, so a framed image opens its page with WebBrowser.navigateToURL instead.
  • The call happens inside the click handler, so the browser treats the new tab as the user’s request rather than a popup.
  • The Attribution is the single source of truth: change its link in the editor and the click follows.

A picture that cycles through frame styles (plain black, oak and gilded) each time it is clicked. The Behavior entity is a child of an Image entity with a Frame, a Selectable and a Signal Emitter whose signal is painting.

FrameStyles.jx
#pragma lifecycle(startup)
const STYLES = [
{ name: 'Black', src: undefined, color: '#111111', thickness: 0.03, gap: 0 },
{ name: 'Oak', src: '/assets/textures/oak.jpg', color: '#ffffff', thickness: 0.08, gap: 0, repeat: 4 },
{ name: 'Gilded', src: '/assets/textures/gold-leaf.jpg', color: '#ffe8a3', thickness: 0.1, gap: 0.03, repeat: 6 },
];
let frame;
let index = 0;
function apply() {
const { name, ...props } = STYLES[index];
frame.setProps(props);
log(`Frame: ${name}`);
}
function startup() {
frame = self.parent.getComponent(FrameComponent);
apply();
on('painting', (event) => {
if (event.eventType !== EventType.Selectable.Select) return;
findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
index = (index + 1) % STYLES.length;
apply();
});
}
  • src: undefined removes the texture: a prop set to undefined takes its default, here a flat colour.
  • repeat tiles the wood or gold texture around the frame so the grain is not stretched.
  • gap leaves a thin space between the picture and the gilded frame, like a mount.
  • The name is taken out of each style before setProps, since it is not a Frame prop.
  • Expecting a frame around a 360 image. A sphere has no edge; the frame appears only on planar surfaces.
  • Sizing a frame for an SVG in metres. An SVG is a 1 × 1 box scaled by its entity; its frame scales with it.
  • Putting a Link on an image or a mesh. A Link is offered on UI entities. Use WebBrowser.navigateToURL from a click handler elsewhere.
  • Opening links from a timer. Browsers block new tabs that do not follow a user’s click or key press.
  • Setting a number as an Attribution value. Every Attribution value must be a string.
  • Using target: '_self' by accident. It replaces the page and ends the visitor’s session in the world.