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

change src attribute of image component with javascript

Community Beginner ,
Aug 06, 2017 Aug 06, 2017

Copy link to clipboard

Copied

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

Views

6.2K

Translate

Translate

Report

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;

});

Votes

Translate

Translate
LEGEND ,
Aug 06, 2017 Aug 06, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Beginner ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Community Beginner ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

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

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

});

Votes

Translate

Translate

Report

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
Community Beginner ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Beginner ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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