Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:22:07+00:00 2026-06-18T05:22:07+00:00

I’m creating a script where image is draggable and can change the image source

  • 0

I’m creating a script where image is draggable and can change the image source when double clicked.

Moving the image works ok and when double clicking the image (event is dblclick) the image changes but same time appears as double where another identical image appears in the original position.

Code is:

var picture = new Image();
picture.onload = function() {
   var picture = new Kinetic.Image({
   x: 10,
   y: 10,
   image: picture,
   draggable: true,
   width: 100,
   height: 200
});

picture.on('dblclick', function() {
   picture.src = 'images/picture2.jpg';
});

layer.add(picture);
stage.add(layer);

}

picture.src = 'images/picture1.jpg';

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:22:09+00:00Added an answer on June 18, 2026 at 5:22 am

    That’s because every time image.src is changed, image onload event is triggered.
    and onload event creates a new Kinetic Image and add to the layer.
    Here is my version of your source code.

    $( function() {
        var stage = new Kinetic.Stage({
          container: 'container',
          width: 578,
          height: 200
        });
        var layer = new Kinetic.Layer();
    
        var yoda = new Kinetic.Image({
          x: 140,
          y: stage.getHeight() / 2 - 59,
          width: 106,
          height: 118,
          draggable:true
        });
    
        var images =[
            'http://www.html5canvastutorials.com/demos/assets/yoda.jpg',
            'http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg',
            'http://www.html5canvastutorials.com/demos/assets/wood-pattern.png'
        ];
        var imgIndex = 0;
        var imageObj = new Image();
        imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/yoda.jpg';
    
        imageObj.onload = function() {
            yoda.setImage(imageObj);
            layer.draw();
        };
    
        yoda.on('dblclick',function() {
            imageObj.src = images[ imgIndex++ % 3 ];
        })
    
        layer.add(yoda);
        stage.add(layer);
    
    });
    

    I believe you follow the tutorial of the site, but it’s not always correct. Also, please remember not to use the same variable picture on your source for image and kinetic object. it’s very confusing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am confused How to use looping for Json response Array in another Array.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.