# Access a png and audio image in a function?

**URL:** <https://forums.solar2d.com/t/access-a-png-and-audio-image-in-a-function/351359>\
**Category:** Newbie Questions\
**Created:** [May 24, 2020, 1:14am UTC](https://forums.solar2d.com/t/access-a-png-and-audio-image-in-a-function/351359 "2020-05-24T01:14:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nerdzmasterz](https://forums.solar2d.com/user_avatar/forums.solar2d.com/nerdzmasterz/32/255_2.png) [@nerdzmasterz](https://forums.solar2d.com/u/nerdzmasterz)\
**Post date:** [May 24, 2020, 1:14am UTC](https://forums.solar2d.com/t/access-a-png-and-audio-image-in-a-function/351359/1 "2020-05-24T01:14:24Z")

</div>

Is there a way to access a png and music/sound effects as objects in a function? I was planning on using a function which would bring up a melody and an image based on what number is randomly generated. While I don’t have the code set up in Lua, I could go over what I want it to do in pseudo-code.

local function theFunction (x, y, z)  
{  
if randomNumber == x  
{  
start y  
display z  
}  
}

Then run it sort of like…

`theFunction(1, melody1, png1)`

I’m not sure if this is doable in Corona or not. Any assistance would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![bgmadclown](https://forums.solar2d.com/user_avatar/forums.solar2d.com/bgmadclown/32/490_2.png) [@bgmadclown](https://forums.solar2d.com/u/bgmadclown)\
**Post date:** [May 24, 2020, 1:19am UTC](https://forums.solar2d.com/t/access-a-png-and-audio-image-in-a-function/351359/2 "2020-05-24T01:19:22Z")

</div>

Sure. You should take a look at the guides: [https://docs.coronalabs.com/guide/index.html#graphics-audio-animation](https://docs.coronalabs.com/guide/index.html#graphics-audio-animation)

---

<div class="post-metadata">

**Author:** ![yosu](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/y/9dc877/32.png) [@yosu](https://forums.solar2d.com/u/yosu)\
**Post date:** [May 24, 2020, 4:31am UTC](https://forums.solar2d.com/t/access-a-png-and-audio-image-in-a-function/351359/3 "2020-05-24T04:31:38Z")

</div>

> [@nerdzmasterz](#):
>
> doable in Corona or not. Any assistance would be greatly appreciated!

Remember to use the [audio.loadSound](https://docs.coronalabs.com/api/library/audio/loadSound.html) to load all audio first. At the end of everything, dispose of it using [audio.dispose](https://docs.coronalabs.com/api/library/audio/dispose.html). If you have sync problem, try other audio file formats like MP3 or WAV.
