main.qml
Qt Code:
  1. import Qt 4.7
  2.  
  3. import "myscript.js" as MyScript
  4.  
  5. Rectangle {
  6. id:main
  7.  
  8. MyScript.myFuction(); // This will execute fine, scope is fine
  9. SecondQML {
  10. }
  11.  
  12. }
To copy to clipboard, switch view to plain text mode 

myscript.js
Qt Code:
  1. function myFuction() {
  2. print('inside my function');
  3. }
To copy to clipboard, switch view to plain text mode 

SecondQML.qml
Qt Code:
  1. Rectangle {
  2.  
  3. MouseArea {
  4. id: mouseArea
  5. anchors.fill: parent
  6. onClicked: {
  7. MyScript.myFunction(); // Will not execute
  8. }
  9. }
  10. }
To copy to clipboard, switch view to plain text mode 

I also tried main.MyScript.myFunction() it is out of scope. I need to be able to reference the same script instance from main.qml and not a newly initiated script from inside secondQML.qml

I can access main from here because of hierarchy but I am not sure why I cannot get to the MyScript property.