Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

change src attribute of image component with javascript

Explorer ,
Aug 06, 2017 Aug 06, 2017

hello..

i want to load images from a webfolder into an image component placeholder choosen from the menu "Fenster" most probably
"Windows" English randomly.

I tried

document.getElementByClasses("uiimage1").src = path + bilder[zufall];

with image component class and instance name between the "..." but this had no effect.


So how do I change the src? Refers html ID and class to the instance name and class of the image component at all?

Thanks in advance

6.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Aug 08, 2017 Aug 08, 2017

//assuming myImage is the instance-name of the component

this.myImage.on("added", function () {

     document.getElementById("myImage").src = ImageURL;

});

Translate
LEGEND ,
Aug 06, 2017 Aug 06, 2017

Why are you using an image component instead of a bitmap symbol? If you were using a bitmap, changing the image source would be easy:

Re: Load dynamic external image in animate cc canvas/javascript

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 07, 2017 Aug 07, 2017

hello thank you.. I think we are close to the solution. It works not yet because the image has not been added to the dom. In as3 it is sth like: var varname(kind) = new libraryElementsConnectionName; addChild(varname); Can you tell me how to do it in javascript for animate cc canvas, please. I'll do an own recherche on this but maybe you are just in the right mood to answer this question. Unfortunatly google is not yet so good for questions about animate cc, javascript and dom.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 07, 2017 Aug 07, 2017

It appears this fellow is accessing the thread in write-only mode.

HELLO? Can you hear me? Why are you using image components?

Well, if you insist on using components for some reason, changing the image is easy:

document.getElementById("STAGE NAME OF THE COMPONENT").src = "whatever.jpg";

But this doesn't work until after the component is initialized, which takes one frame.

And you probably shouldn't be using components anyway.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 07, 2017 Aug 07, 2017

I already tried this.myMC.children[0].image.src = "1.jpg"; with a movieclib with a bitmap in it and
document.getElementById("STAGE NAME OF THE COMPONENT").src = "whatever.jpg"; with an image component

and I tried Instance Name, Name and with the name I wrote right next to the name in the library. Till now no img has shown up. Are you sure the image is automatically added to the dom by the software and does not need to be initialized to the dom before it can be added to the stage dynamically?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Aug 08, 2017 Aug 08, 2017

//assuming myImage is the instance-name of the component

this.myImage.on("added", function () {

     document.getElementById("myImage").src = ImageURL;

});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2017 Aug 08, 2017

screenshot.jpg

Currently I am using this simplified example code:

var Images = new Array("img1", "img2", "img3", "img4", "img5");

function doSomething() {

    alert('hi ');

    var min = 1;

    var max = 5;

    var x = (Math.random() * (max - min)) + min;

    this.links1.children[0].image = Images;

    }

(function loop() {

    var rand = Math.round(Math.random() * (1000 - 500)) + 500;

    setTimeout(function() {

            doSomething();

            loop(); 

    }, rand);

}());

The complete animation inclusive js is place at the first frame.

image does not show up. browser console says: "typeError: this.links1 is undefined"
If I leave away the this it says "typeError: links1 is undefined"

Can this problem be solved by exactly correctly programming or is it a bug?

Sincerely

Felix Czeck

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2017 Aug 08, 2017

Thank you but this works only as standalone, but not within another function I can loop with random intervals and choose from an array of images.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2017 Aug 08, 2017
LATEST

You can't change anything on any component or any movie clip until it's fully initialized.

So wait a frame before trying to change it.

Just wait a frame.

Wait a frame.

WAIT.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines