Copy link to clipboard
Copied
Hi!
We're making an HTML ad,
but some of the interfaces we're trying to upload it to
require everything to be included in one single HTML file.
So we are trying to embed a spriteSheet (image) to the exported html file.
we succeded in interpreting the image into code,
but we are struggling with where to enter it, and how to link to it.
Currently there's a java script (inside the html) that links to an external image file (you can search inside the file the word "HELP").
The HTML (called: "TEST.html"):
<!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>TEST</title>
<!-- write your code here -->
<script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
<script>
(function (lib, img, cjs, ss) {
var p; // shortcut to reference prototypes
// library properties:
lib.properties = {
width: 550,
height: 400,
fps: 25,
color: "#555555",
opacity: 1.00,
manifest: [
{src:"images/TEST_atlas_NP_.jpg?1509437705584"/*HELP!*/, id:"TEST_atlas_NP_"}
]
};
lib.ssMetadata = [
{name:"TEST_atlas_NP_", frames: [[0,787,320,180],[0,0,564,785]]}
];
// symbols:
(lib.cat = function() {
this.spriteSheet = ss["TEST_atlas_NP_"];
this.gotoAndStop(0);
}).prototype = p = new cjs.Sprite();
(lib.GirlImg = function() {
this.spriteSheet = ss["TEST_atlas_NP_"];
this.gotoAndStop(1);
}).prototype = p = new cjs.Sprite();
(lib.GirlImg_mc = function(mode,startPosition,loop) {
this.initialize(mode,startPosition,loop,{});
// Layer 1
this.instance = new lib.GirlImg();
this.instance.parent = this;
this.instance.setTransform(0,0,0.34,0.34);
this.timeline.addTween(cjs.Tween.get(this.instance).wait(1));
}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(0,0,192,267.3);
(lib.Cat_mc = function(mode,startPosition,loop) {
this.initialize(mode,startPosition,loop,{});
// Layer 1
this.instance = new lib.cat();
this.instance.parent = this;
this.timeline.addTween(cjs.Tween.get(this.instance).wait(1));
}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(0,0,320,180);
// stage content:
(lib.TEST = function(mode,startPosition,loop) {
this.initialize(mode,startPosition,loop,{});
// Imgs
this.instance = new lib.Cat_mc();
this.instance.parent = this;
this.instance.setTransform(170.5,302,1,1,0,0,0,160,90);
this.instance_1 = new lib.GirlImg_mc();
this.instance_1.parent = this;
this.instance_1.setTransform(435.1,155.6,1,1,0,0,0,96,133.6);
this.timeline.addTween(cjs.Tween.get({}).to({state:[{t:this.instance_1},{t:this.instance}]}).wait(1));
}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(285.5,222,520.6,370.1);
})(lib = lib||{}, images = images||{}, createjs = createjs||{}, ss = ss||{});
var lib, images, createjs, ss;
</script>
<script>
var canvas, stage, exportRoot;
function init() {
canvas = document.getElementById("canvas");
images = images||{};
ss = ss||{};
var loader = new createjs.LoadQueue(false);
loader.addEventListener("fileload", handleFileLoad);
loader.addEventListener("complete", handleComplete);
loader.loadManifest(lib.properties.manifest);
}
function handleFileLoad(evt) {
if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
}
function handleComplete(evt) {
//This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
var queue = evt.target;
var ssMetadata = lib.ssMetadata;
for(i=0; i<ssMetadata.length; i++) {
ss[ssMetadata.name] = new createjs.SpriteSheet( {"images": [queue.getResult(ssMetadata.name)], "frames": ssMetadata.frames} )
}
exportRoot = new lib.TEST();
stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
//Registers the "tick" event listener.
createjs.Ticker.setFPS(lib.properties.fps);
createjs.Ticker.addEventListener("tick", stage);
//Code to support hidpi screens and responsive scaling.
(function(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 = w*sRatio+'px';
canvas.style.height = h*sRatio+'px';
stage.scaleX = pRatio*sRatio;
stage.scaleY = pRatio*sRatio;
lastW = iw; lastH = ih; lastS = sRatio;
}
})(true,'height',true,1);
}
</script>
<!-- write your code here -->
</head>
<body onload="init();" style="margin:0px;">
<canvas id="canvas" width="550" height="400" style="display: block; background-color:rgba(85, 85, 85, 1.00)"></canvas>
</body>
</html>
<!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>TEST</title>
<!-- write your code here -->
<script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
<script>
(function (lib, img, cjs, ss) {
var p; // shortcut to reference prototypes
// library properties:
lib.properties = {
width: 550,
height: 400,
fps: 25,
color: "#555555",
opacity: 1.00,
manifest: [
{src:"images/TEST_atlas_NP_.jpg?1509437705584"/*HELP!*/, id:"TEST_atlas_NP_"}
]
};
lib.ssMetadata = [
{name:"TEST_atlas_NP_", frames: [[0,787,320,180],[0,0,564,785]]}
];
// symbols:
(lib.cat = function() {
this.spriteSheet = ss["TEST_atlas_NP_"];
this.gotoAndStop(0);
}).prototype = p = new cjs.Sprite();
(lib.GirlImg = function() {
this.spriteSheet = ss["TEST_atlas_NP_"];
this.gotoAndStop(1);
}).prototype = p = new cjs.Sprite();
(lib.GirlImg_mc = function(mode,startPosition,loop) {
this.initialize(mode,startPosition,loop,{});
// Layer 1
this.instance = new lib.GirlImg();
this.instance.parent = this;
this.instance.setTransform(0,0,0.34,0.34);
this.timeline.addTween(cjs.Tween.get(this.instance).wait(1));
}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(0,0,192,267.3);
(lib.Cat_mc = function(mode,startPosition,loop) {
this.initialize(mode,startPosition,loop,{});
// Layer 1
this.instance = new lib.cat();
this.instance.parent = this;
this.timeline.addTween(cjs.Tween.get(this.instance).wait(1));
}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(0,0,320,180);
// stage content:
(lib.TEST = function(mode,startPosition,loop) {
this.initialize(mode,startPosition,loop,{});
// Imgs
this.instance = new lib.Cat_mc();
this.instance.parent = this;
this.instance.setTransform(170.5,302,1,1,0,0,0,160,90);
this.instance_1 = new lib.GirlImg_mc();
this.instance_1.parent = this;
this.instance_1.setTransform(435.1,155.6,1,1,0,0,0,96,133.6);
this.timeline.addTween(cjs.Tween.get({}).to({state:[{t:this.instance_1},{t:this.instance}]}).wait(1));
}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(285.5,222,520.6,370.1);
})(lib = lib||{}, images = images||{}, createjs = createjs||{}, ss = ss||{});
var lib, images, createjs, ss;
</script>
<script>
var canvas, stage, exportRoot;
function init() {
canvas = document.getElementById("canvas");
images = images||{};
ss = ss||{};
var loader = new createjs.LoadQueue(false);
loader.addEventListener("fileload", handleFileLoad);
loader.addEventListener("complete", handleComplete);
loader.loadManifest(lib.properties.manifest);
}
function handleFileLoad(evt) {
if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
}
function handleComplete(evt) {
//This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
var queue = evt.target;
var ssMetadata = lib.ssMetadata;
for(i=0; i<ssMetadata.length; i++) {
ss[ssMetadata.name] = new createjs.SpriteSheet( {"images": [queue.getResult(ssMetadata.name)], "frames": ssMetadata.frames} )
}
exportRoot = new lib.TEST();
stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
//Registers the "tick" event listener.
createjs.Ticker.setFPS(lib.properties.fps);
createjs.Ticker.addEventListener("tick", stage);
//Code to support hidpi screens and responsive scaling.
(function(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 = w*sRatio+'px';
canvas.style.height = h*sRatio+'px';
stage.scaleX = pRatio*sRatio;
stage.scaleY = pRatio*sRatio;
lastW = iw; lastH = ih; lastS = sRatio;
}
})(true,'height',true,1);
}
</script>
<!-- write your code here -->
</head>
<body onload="init();" style="margin:0px;">
<canvas id="canvas" width="550" height="400" style="display: block; background-color:rgba(85, 85, 85, 1.00)"></canvas>
</body>
</html>
The Sprite Sheet (called: "TEST_atlas_NP_.jpg", originaly being exported to "image" folder, near the html file) :
This is the result we're searching for, once we open the html file:
Tnx!
The src of an image can be a file, but it can also just be Base64 data. See the answer given here:
https://www.reddit.com/r/createjs/comments/4dfldb/how_do_i_use_base24_instead_of_external_library/
Copy link to clipboard
Copied
The src of an image can be a file, but it can also just be Base64 data. See the answer given here:
https://www.reddit.com/r/createjs/comments/4dfldb/how_do_i_use_base24_instead_of_external_library/
Copy link to clipboard
Copied
Hello,There are a little different in aimate2018, could you point out what we shoud modified with your code?.
such like there are not a variable which named "images" now...
Copy link to clipboard
Copied
Finally I found this https://medium.com/@davidwallin/how-to-get-ads-created-in-adobe-animate-cc-to-work-on-doub leclick-f...
It Works for me.
He used img base64 to Bitmap.when you export image not with atlas.symbols' section would be bitmap not sprite.
Here is my file=>0430_labar_FB_Playable_IMGbase64_notAtlas_Nil_20180711_1.html - Google Drive
Find more inspiration, events, and resources on the new Adobe Community
Explore Now