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

How do I Import another JSX file to My Main JSX File

New Here ,
May 09, 2023 May 09, 2023

Hey, So I am trying to seprate code for readablity. I have two files so far. I am trying to import the file into the main file. I tried using #include but i got an error saying I could not use it outside a class. I saw online another example //@include but that does not work. It just comments out the import. What is the proper way of importing a file ?

TOPICS
How to , Import and export , Scripting , UXP Scripting
1.2K
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 2 Correct answers

Community Expert , May 09, 2023 May 09, 2023
Translate
Community Expert , May 09, 2023 May 09, 2023

This example works for me. Create a file named HelloWorld.jsxinc with a function you want to run:

 

/**
* Discription 
* @ param a string
* @ return string 
*/

function helloWorld(s){
  return "From Hello World: " + s
}

 

Save the .jsxinc file in the same directory with the script that will include it—here is an example script that incudes the .jsxinc file:

 

#include "HelloWorld.jsxinc"
alert(helloWorld("Hi There!"))

 

The include sample run:

 

Screen Shot 16.pngexpand image

 

Translate
Community Expert ,
May 09, 2023 May 09, 2023
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 ,
Dec 03, 2024 Dec 03, 2024
LATEST

thank you

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
Community Expert ,
May 09, 2023 May 09, 2023

This example works for me. Create a file named HelloWorld.jsxinc with a function you want to run:

 

/**
* Discription 
* @ param a string
* @ return string 
*/

function helloWorld(s){
  return "From Hello World: " + s
}

 

Save the .jsxinc file in the same directory with the script that will include it—here is an example script that incudes the .jsxinc file:

 

#include "HelloWorld.jsxinc"
alert(helloWorld("Hi There!"))

 

The include sample run:

 

Screen Shot 16.pngexpand image

 

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
Community Expert ,
May 09, 2023 May 09, 2023

@Victor29751988fsbx , if solution by @rob day does not work, could you post your separate code file, so that we can help?

Best regards
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
New Here ,
May 09, 2023 May 09, 2023

Thanks they have been really helpful

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