# Instantiate variable of outside class

**URL:** <https://discourse.processing.org/t/instantiate-variable-of-outside-class/19088>\
**Category:** Libraries\
**Created:** [March 27, 2020, 4:28pm UTC](https://discourse.processing.org/t/instantiate-variable-of-outside-class/19088 "2020-03-27T16:28:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [March 27, 2020, 4:28pm UTC](https://discourse.processing.org/t/instantiate-variable-of-outside-class/19088/1 "2020-03-27T16:28:47Z")

</div>

GoodMorning, I have a question about of usage `this` parameter in contructor class.  
My minimal code is:

```auto
import processing.video.*;
class MediaLoad {
  File file;
  Movie mov;
  MediaLoad (File _file) {
    _file = file;
    mov = new Movie(this,file.getAbsolutePath());
  }
  
}
MediaLoad ml;

```

when I digit the line:  
`mov = new Movie(this,file.getAbsolutePath());`  
the red allert compare with:  
_The constructor “Movie(MediaLoad, String)” does not exist_

In the Object documentation is explained the `this` parameter is parent and the error confirm that.  
Is a way to instantiate my `mov` variable inside another class?

Thanks !  
Dennis.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 27, 2020, 4:35pm UTC](https://discourse.processing.org/t/instantiate-variable-of-outside-class/19088/2 "2020-03-27T16:35:25Z")

</div>

- Java’s keyword `this` is of the same datatype as the `class` it’s being used.
- Movie’s constructor expects datatype PApplet as its 1st parameter, not a MediaLoad.
- A better approach would be to request an already instantiated Movie instance in place of a File for your `class` MediaLoad’s constructor.

---

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [March 27, 2020, 4:37pm UTC](https://discourse.processing.org/t/instantiate-variable-of-outside-class/19088/3 "2020-03-27T16:37:46Z")

</div>

Thank You GoToLoop, Very fast response!  
I try your way…

---

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [March 27, 2020, 5:30pm UTC](https://discourse.processing.org/t/instantiate-variable-of-outside-class/19088/4 "2020-03-27T17:30:43Z")

</div>

With GoToLoop suggestion i found the way:

```auto
import processing.video.*;

class MediaLoad {

  ArrayList<File> mediaList = new ArrayList<File>();
  ArrayList<File> fileArray; // array con i file dell'articolo selezionato
  ArrayList<Movie> videoList; // array con i video caricati

  MediaLoad(ArrayList<File> _mediaList) {
    mediaList = _mediaList;
  }

  void load() {
    boolean videoTrovato = false;
    fileArray = new ArrayList<File>();
    for (File file : mediaList) {
      if (!file.getName().contains(".thum") && !file.isDirectory()) {
        if ( // carico i video in array
          file.getName().contains(".mov") 
          || file.getName().contains(".mp4")
          || file.getName().contains(".avi")) {
          videoTrovato = true;
          fileArray.add(file);
        } // fine if
      } // fine if non thumb
    } // fine for mediaList
    if (videoTrovato) {
      loadMovie(fileArray, videoList);
    } // fine if videoTrovato
  } // fine load;
} // fine class

// -------------------------------------------------------------------------

void loadMovie(ArrayList<File> fileList, ArrayList<Movie> movList) {
  for (File file : fileList) {
    movList.add(new Movie(this, file.getAbsolutePath()));
  }
}

```

the code is only an extract of my MediaLoad class  
Have a Nice Coding Guys !!!
