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

2 double quotes are converted to 2 single quotes, an error occurs

Contributor ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

var strAlert = "";

2 single quotes:var strAlert = ''; report error:SyntaxError: unterminated string literal

Is there a way to solve

TOPICS
ActionScript , Code , Error , Exchange extensions

Views

486

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

Engaged , Mar 03, 2023 Mar 03, 2023

I think, the MMExecite() method is similar to eval(), so I tested the string with eval() method and the result is the same error - unterminated string literal.
I noticed that you have unescaped "\n" symbols in the alert string. After escaping them, the code works as supposed. Here it is:

 

function onBtnClick( e:MouseEvent ):void{
	var jsfl:String = new String();
	
	jsfl += "var arrLayers = fl.getDocumentDOM().getTimeline().getSelectedLayers();\n var nCurrentFrame = fl.getDocumentDOM().getTimeline(
...

Votes

Translate

Translate
Community Expert ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

Hi.

 

Both examples using single and double quotes work for me without a problem.

 

Can you provide more details?

 

Also make sure that you're using the standard quotes because sometimes we copy some examples from the Internet but they came with different types of quotes.

 

Regards,

JC

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
Contributor ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

function onBtnClick(e:MouseEvent):void {

var jsfl:String = new String();

jsfl += "var arrLayers = fl.getDocumentDOM().getTimeline().getSelectedLayers();\n var nCurrentFrame = fl.getDocumentDOM().getTimeline().currentFrame;\nalert('Make sure:\n - the playhead is in a blank frame before your layers start.\n - you have fully selected your layers (whilst holding SHIFT)');\nvar strOffSet = prompt('Frames to stagger your layers by?');\nvar nOffSet = 5;\nvar nFramesToAdd;\nvar strAlert = '';\ntry\n{\nnOffSet = parseInt(strOffSet);\n}\ncatch(e)\n{\nnOffSet = 5;\n}\nvar nLongestLayer = fl.getDocumentDOM().getTimeline().frameCount + nOffSet;\narrLayers.reverse();\nfor(var i=0; i < arrLayers.length; i++)\n{\nnFramesToAdd = (i+1)*nOffSet;\nfl.getDocumentDOM().getTimeline().currentLayer = arrLayers[i];\nfl.getDocumentDOM().getTimeline().insertFrames(nFramesToAdd, false, nCurrentFrame);\nnLongestLayer+=nOffSet;\n}\nnLongestLayer-=nOffSet;\nstrAlert = 'Offset ' + i + ' layers by ' + nOffSet + ' frames';\nvar arrAllLayers = fl.getDocumentDOM().getTimeline().layers;\nvar nWhereToAdd;\nfor(var j=0; j < arrAllLayers.length; j++)\n{\nif(arrAllLayers[j].frameCount < nLongestLayer)\n{\nnFramesToAdd = nLongestLayer - arrAllLayers[j].frameCount;\nnWhereToAdd = arrAllLayers[j].frameCount;\nfl.getDocumentDOM().getTimeline().currentLayer = j;\nfl.getDocumentDOM().getTimeline().insertFrames(nFramesToAdd, false, nWhereToAdd);\n}\n}\nalert(strAlert);\n;";	
		
MMExecute(jsfl);

}

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 Expert ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

Thanks.

 

I cannot test in an actual MMExecute call right now, but running this string in a regular AS3 and HTML5 Canvas document give me no errors.

 

You can break down your string in multiple lines like this so it will be easier for you to spot problems:

var string = "";

string += "var arrLayers = fl.getDocumentDOM().getTimeline().getSelectedLayers();\n";
string += "var nCurrentFrame = fl.getDocumentDOM().getTimeline().currentFrame;\n";
string += "alert('Make sure:\n - the playhead is in a blank frame before your layers start.\n - you have fully selected your layers (whilst holding SHIFT)');\n";
string += "var strOffSet = prompt('Frames to stagger your layers by?');\n";
string += "var nOffSet = 5;\n";
string += "var nFramesToAdd;\n";
string += "var strAlert = '';\n";
string += "try\n";
string += "{\n";
string += "nOffSet = parseInt(strOffSet);\n";
string += "}\n";
string += "catch(e)\n";
string += "{\n";
string += "nOffSet = 5;\n";
string += "}\n";
string += "var nLongestLayer = fl.getDocumentDOM().getTimeline().frameCount + nOffSet;\n";
string += "arrLayers.reverse();\n";
string += "for(var i=0; i < arrLayers.length; i++)\n";
string += "{\n";
string += "nFramesToAdd = (i+1)*nOffSet;\n";
string += "fl.getDocumentDOM().getTimeline().currentLayer = arrLayers[i];\n";
string += "fl.getDocumentDOM().getTimeline().insertFrames(nFramesToAdd, false, nCurrentFrame);\n";
string += "nLongestLayer+=nOffSet;\n";
string += "}\n";
string += "nLongestLayer-=nOffSet;\n";
string += "strAlert = 'Offset ' + i + ' layers by ' + nOffSet + ' frames';\n";
string += "var arrAllLayers = fl.getDocumentDOM().getTimeline().layers;\n";
string += "var nWhereToAdd;\n";
string += "for(var j=0; j < arrAllLayers.length; j++)\n";
string += "{\n";
string += "if(arrAllLayers[j].frameCount < nLongestLayer)\n";
string += "{\n";
string += "nFramesToAdd = nLongestLayer - arrAllLayers[j].frameCount;\n";
string += "nWhereToAdd = arrAllLayers[j].frameCount;\n";
string += "fl.getDocumentDOM().getTimeline().currentLayer = j;\n";
string += "fl.getDocumentDOM().getTimeline().insertFrames(nFramesToAdd, false, nWhereToAdd);\n";
string += "}\n";
string += "}\n";
string += "alert(strAlert);";

 

Regards,

JC

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
Engaged ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

LATEST

I think, the MMExecite() method is similar to eval(), so I tested the string with eval() method and the result is the same error - unterminated string literal.
I noticed that you have unescaped "\n" symbols in the alert string. After escaping them, the code works as supposed. Here it is:

 

function onBtnClick( e:MouseEvent ):void{
	var jsfl:String = new String();
	
	jsfl += "var arrLayers = fl.getDocumentDOM().getTimeline().getSelectedLayers();\n var nCurrentFrame = fl.getDocumentDOM().getTimeline().currentFrame;\nalert('Make sure:\\n - the playhead is in a blank frame before your layers start.\\n - you have fully selected your layers (whilst holding SHIFT)');\nvar strOffSet = prompt('Frames to stagger your layers by?');\nvar nOffSet = 5;\nvar nFramesToAdd;\nvar strAlert = '';\ntry\n{\nnOffSet = parseInt(strOffSet);\n}\ncatch(e)\n{\nnOffSet = 5;\n}\nvar nLongestLayer = fl.getDocumentDOM().getTimeline().frameCount + nOffSet;\narrLayers.reverse();\nfor(var i=0; i < arrLayers.length; i++)\n{\nnFramesToAdd = (i+1)*nOffSet;\nfl.getDocumentDOM().getTimeline().currentLayer = arrLayers[i];\nfl.getDocumentDOM().getTimeline().insertFrames(nFramesToAdd, false, nCurrentFrame);\nnLongestLayer+=nOffSet;\n}\nnLongestLayer-=nOffSet;\nstrAlert = 'Offset ' + i + ' layers by ' + nOffSet + ' frames';\nvar arrAllLayers = fl.getDocumentDOM().getTimeline().layers;\nvar nWhereToAdd;\nfor(var j=0; j < arrAllLayers.length; j++)\n{\nif(arrAllLayers[j].frameCount < nLongestLayer)\n{\nnFramesToAdd = nLongestLayer - arrAllLayers[j].frameCount;\nnWhereToAdd = arrAllLayers[j].frameCount;\nfl.getDocumentDOM().getTimeline().currentLayer = j;\nfl.getDocumentDOM().getTimeline().insertFrames(nFramesToAdd, false, nWhereToAdd);\n}\n}\nalert(strAlert);";
	
	MMExecute( jsfl );
}

 



- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

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