Skip to main content
philipo56490068
Participating Frequently
February 16, 2022
Answered

JS error only when instance has a name

  • February 16, 2022
  • 1 reply
  • 623 views

Hi,

 

can't figure out this one, hope someone can help me.

 

Canvas document with an instance of a Movie Clip on a separate layer. On the MC some script (like a console.log, doesn't matter). There is also a camera with some script in the scene.

When I assign a name to the MC and publish, I get

Uncaught TypeError: Cannot read properties of undefined (reading 'resetButton')

 in DevTools. When the MC has no instance name, there is no error. When I delete the camera or completely delete the script on the MC intance, there is also no error.

 

Am I missing something fundamental about instances? My understanding is that every instance needs to have a name in order to be adressed by scripts.

 

thank you

Philip

    This topic has been closed for replies.
    Correct answer kglad

    i generally don't download and correct files unless i'm hired or there's something of particular interest to me.

     

    in your  case i thought there might be something interesting so i downloaded and debugged your fla.  your error was pointed out in my first message and confirmed with that first download.

     

    if you want me to continue to help and download another version of your fla, you'll need to hire me.


    addendum: i took another look and noted you had not assigned an instance name to the yellow square in instance_name2.  so, i did that and saw the error, but i also noticed the yellow square is in the camera layer and that's suspicious.

     

    after moving the yellow square to its own layer, everything worked. again:

     

    bottomline: put nothing in the camera layer after adding it.  lock it and leave it locked.

    1 reply

    kglad
    Community Expert
    February 16, 2022

    what's the script?

    philipo56490068
    Participating Frequently
    February 16, 2022

    This is the camera script. I deleted any other scripts in the scene.

    var root = this;
    createjs.Touch.enable(stage);
    var dpr = window.devicePixelRatio;
    CameraObject = AdobeAn.VirtualCamera.getCamera(exportRoot);
    
    // Custom
    var scaleZoomedOut = 2.5;
    var scaleZoomedIn = 0.8;
    
    
    // Cache initial values
    var env = {
    	camInitX: CameraObject.camera.x,
    	camInitY: CameraObject.camera.y
    };
    
    
    
    //root.bg.on("pressmove", drag);
    
    function drag(event) {
    	//root.removeEventListener("click", zoomIn);
    	CameraObject.camera.x = event.stageX / dpr;
    	CameraObject.camera.y = event.stageY / dpr;
    }
    
    
    root.bg.on("click", newCenter);
    
    function newCenter(event){
    	console.log(event.stageX/dpr);
    	if(!zoomed){
    		CameraObject.setZoom(250);
    		createjs.Tween.get(CameraObject.camera, {
    			override: true
    		}).to({
    			x: event.stageX / dpr,
    			y: event.stageY / dpr
    		}, 800, createjs.Ease.sineOut);
    		//CameraObject.camera.x = event.stageX / dpr;
    		//CameraObject.camera.y = event.stageY / dpr;
    	}
    }
    
    
    // old, for reference
    function zoom(event) {
    
    	// zoom in
    	if (!zoomed) {
    		createjs.Tween.get(CameraObject.camera, {
    			override: true
    		}).to({
    			x: event.stageX / dpr,
    			y: event.stageY / dpr,
    			scaleX: scaleZoomedIn,
    			scaleY: scaleZoomedIn
    		}, 800, createjs.Ease.sineOut);
    		zoomed = true;
    	}
    
    	//zoom out
    	else {
    		createjs.Tween.get(CameraObject.camera, {
    			override: true
    		}).to({
    			x: env.camInitX / dpr,
    			y: env.camInitY / dpr/*,
    			scaleX: scaleZoomedOut,
    			scaleY: scaleZoomedOut*/
    		}, 800, createjs.Ease.sineOut);
    		zoomed = false;
    	}
    }

     

    philipo56490068
    Participating Frequently
    February 17, 2022

    where's bg defined?


    It wasn't. Replaced the original bg with a placeholder for uploading and forgot to name it, sorry. Still the same error, though.

    https://www.dropbox.com/s/7i5w30dk7wtf31x/instance_name2.fla?dl=0