HTML Templates with dynamic text fields

hi everyone, I’m looking for some help with the HTML templates I’ve just started working with them and I’m just learning programing. I’m working with Animate CC 2019. I’m creating a lower 3rd template. I have the animation working and can call it in using the html tool. I would like to be able to use the CCG client to change the text fields. but I’m not sure how, I tried using the wiki page but couldn’t get it to work. i’m using CG 2.2.0

bellow is my code and I have attached it, INN HTML test.html (4.5 KB)

        <!DOCTYPE html>
<!--
	NOTES:
	1. All tokens are represented by '$' sign in the template.
	2. You can write your code only wherever mentioned.
	3. All occurrences of existing tokens will be replaced by their appropriate values.
	4. Blank lines will be removed automatically.
	5. Remove unnecessary comments before creating your template.
-->
<html>
<head>
<meta charset="UTF-8">
<meta name="authoring-tool" content="Adobe_Animate_CC">
<title>INN HTML test</title>
<!-- write your code here -->
<script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
<script src="INN HTML test.js"></script>
<script>
// Global Scripts
	var json = {};
saved = saved.replace(/^(<templateData>|<componentData>|<data>)|(<\/templateData>|<\/componentData>|<\/data>)$/ig, );
try {
    json = JSON.parse(decodeURI(saved));
} catch (e) {}
for (var key in json) {
    sym.$(key).html(json[key]);
}</script>
<script>
var canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation;
function init() {
	canvas = document.getElementById("canvas");
	anim_container = document.getElementById("animation_container");
	dom_overlay_container = document.getElementById("dom_overlay_container");
	var comp=AdobeAn.getComposition("5DBB8DE787B53148940396A431E80D97");
	var lib=comp.getLibrary();
	var loader = new createjs.LoadQueue(false);
	loader.addEventListener("fileload", function(evt){handleFileLoad(evt,comp)});
	loader.addEventListener("complete", function(evt){handleComplete(evt,comp)});
	var lib=comp.getLibrary();
	loader.loadManifest(lib.properties.manifest);
}
function handleFileLoad(evt, comp) {
	var images=comp.getImages();	
	if (evt && (evt.item.type == "image")) { images[evt.item.id] = evt.result; }	
}
function handleComplete(evt,comp) {
	//This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
	var lib=comp.getLibrary();
	var ss=comp.getSpriteSheet();
	var queue = evt.target;
	var ssMetadata = lib.ssMetadata;
	for(i=0; i<ssMetadata.length; i++) {
		ss[ssMetadata[i].name] = new createjs.SpriteSheet( {"images": [queue.getResult(ssMetadata[i].name)], "frames": ssMetadata[i].frames} )
	}
	exportRoot = new lib.INNHTMLtest();
	stage = new lib.Stage(canvas);	
	//Registers the "tick" event listener.
	fnStartAnimation = function() {
		stage.addChild(exportRoot);
		createjs.Ticker.setFPS(lib.properties.fps);
		createjs.Ticker.addEventListener("tick", stage);
	}	    
	//Code to support hidpi screens and responsive scaling.
	function makeResponsive(isResp, respDim, isScale, scaleType) {		
		var lastW, lastH, lastS=1;		
		window.addEventListener('resize', resizeCanvas);		
		resizeCanvas();		
		function resizeCanvas() {			
			var w = lib.properties.width, h = lib.properties.height;			
			var iw = window.innerWidth, ih=window.innerHeight;			
			var pRatio = window.devicePixelRatio || 1, xRatio=iw/w, yRatio=ih/h, sRatio=1;			
			if(isResp) {                
				if((respDim=='width'&&lastW==iw) || (respDim=='height'&&lastH==ih)) {                    
					sRatio = lastS;                
				}				
				else if(!isScale) {					
					if(iw<w || ih<h)						
						sRatio = Math.min(xRatio, yRatio);				
				}				
				else if(scaleType==1) {					
					sRatio = Math.min(xRatio, yRatio);				
				}				
				else if(scaleType==2) {					
					sRatio = Math.max(xRatio, yRatio);				
				}			
			}			
			canvas.width = w*pRatio*sRatio;			
			canvas.height = h*pRatio*sRatio;
			canvas.style.width = dom_overlay_container.style.width = anim_container.style.width =  w*sRatio+'px';				
			canvas.style.height = anim_container.style.height = dom_overlay_container.style.height = h*sRatio+'px';
			stage.scaleX = pRatio*sRatio;			
			stage.scaleY = pRatio*sRatio;			
			lastW = iw; lastH = ih; lastS = sRatio;            
			stage.tickOnUpdate = false;            
			stage.update();            
			stage.tickOnUpdate = true;		
		}
	}
	makeResponsive(false,'both',false,1);	
	AdobeAn.compositionLoaded(lib.properties.id);
	fnStartAnimation();
}
</script>
<!-- write your code here -->
</head>
<body onload="init();" style="margin:0px;">
	<div id="animation_container" style="background-color:rgba(#ffff); width:1920px; height:1080px">
		<canvas id="canvas" width="1920" height="1080" style="position: absolute; display: block; background-color:rgba(#ffff);"></canvas>
		<div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:1920px; height:1080px; position: absolute; left: 0px; top: 0px; display: block;">
		</div>
	</div>
</body>
</html>
1 Like

I have created a small set of tools to work with HTML templates. One of these tools is an adapter to connect CasparCG with Adobe Animate HTML5 Canvas templates: webcg-adobe-animate-adapter. This adapter has these features:

  • Support of ACMP commands play, next, stop, update and invoke.
  • Support of “intro” and “outro” labels.
  • Support of three data formats: plain JavaScript object, JSON and the templateData XML format.
  • Automatic update of template instances according to the provided data via update.
  • The adapter comes with lazy-loaded development tools that provide a user interface to edit the template data and invoke the above commands.

Here are useful resources:

6 Likes

Hi Reto,

that looks very promising, I will test it asap. Thank you for sharing.

this looks great I’ll give it a try thanks a lot for sharing

Great stuff, thanks for sharing.

Thank you guys for the flowers and the testing. I am taking the liberty to show a screenshot with @LateGreat’s template he gave me to help him:

@LateGreat: I recommend to add overflow: hidden to your body tag.

1 Like

Hi Reto,

I’m really liking the adapter. Is it possible to create dynamic images using this? For example, I’m trying to add team logos that ideally could be changed using the Caspar keys by typing in the team logo.

It works the same way as in Flash: You need to give a URL formsted string and set this as source of an image object.

Hi Didi, may I ask what are the steps to do this in Adobe Animate?

I never did that in Animate. It‘s the same as setting a text, just set the image source.

Hi Didi, I’m still a little confused. I’m trying to create an HTML template within Adobe Animate. Flash has been discontinued by Adobe, so I am not sure how to set an image source to a template key within Adobe Animate.

How do you do it for textfields? Must be some JavaScript code, isn‘t it? Insted of the text set the source of the image. As I said I never did it in Animate, so I don‘t know how you do dynamic text in HTML using animate.

Privacy Policy   Terms of Service