# Accessing Files in Code

### Introduction

Any file added to a Screen or Entity will have a corresponding member in code which represents the already-loaded file. You can access this object in custom code without having to worry about whether it has been loaded or when to load it (at least under default settings).

### Example

To see how a file is accessed in code:

1. Create a new Screen called "TestScreen"
2. Find a .png through windows explorer
3. Drag+drop the .png into your TestScreen's Files in Glue
4. Notice that the newly-added File will indicate which type it will load to at runtime

   <figure><img src="/files/JCSavnvAjoxFPIHpIr77" alt=""><figcaption></figcaption></figure>
5. Open TestScreen.cs in Visual Studio
6. Add the following code to CustomInitialize:

```
// My file was called "Slug.png" so my member name is Slug
// You may need to change the member name to match your file name
Sprite sprite = SpriteManager.AddSprite(Slug);
```

Note:Since the purpose of the code above is to simply show that the file added to TestScreen can be accessed in code, it does not cover removal of the Sprite. In an actual game you would want to keep track of the Sprite at Screen level and remove it in the Screen's CustomDestroy. Not doing so would result in your game crashing when you transition to a different Screen.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/flatredball/glue-reference/files/glue-reference-accessing-in-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
