Page tree
Skip to end of metadata
Go to start of metadata

This guide explains how to use Assets in your project.

What is Assets ?

Assets is a folder which is placed under the app project folder.

You can use this folder to directly access the files inside it. Instead of the “Resources” and “Images”, this folder can be reached by file operations such as read. Additionally, the Assets folder is available for each kind of device independently: You don’t need to use separate folders as you do in Resources.

The Database file can also be placed under Assets folder.

During runtime, Assets folder is a read-only folder.

While generating exporting packages, codes will be placed in Assets folder.

In order to change a file in Assets, it should be copied into data and then it can be changed.

By using the below command, you can reach to related directory(assets://) :

alert(SMF.IO.applicationAssetsDirectory);

Example

Using an icon with assets

First, let's place a ".png" file inside the Assets folder.

Now, let's create an image object and see how we can use "myicon.png" :

var myImage = new SMF.UI.Image({
	left : "22%",
	top : "42%",
	width : "55%",
	height : "25%",
	image : "assets://myicon.png",
	changeAnimation : "fade",
	imageFillType : SMF.UI.ImageFillType.STRETCH
});
page1.add(myImage);

After you add this image object (myImage) to the related page, it will look like below :

Reading a txt file from assets

As a second example, let's see how you can read a file in the assets folder.

First, create a ".txt" file or you can use an existing one. Secondly, place this file into the assets folder as below :

Now, let's create a textButton object, and when pressed to textButton, it will run the read method :

var myButton = new SMF.UI.TextButton({
	left : "12%",
	top : "25%",
	width : "75%",
	height : "10%",
	text : "read myFile.txt",
	onPressed : function (e) {
		var streamReader = new SMF.IO.FileStream("assets://", "myFile.txt", SMF.IO.StreamType.READ);
		var myText = streamReader.readToEnd();
		alert(myText);
	}
});
page1.add(myButton);

Add this textButton object(myButton) to the related page. When you press myButton, it will look like below :



Reading an XML file from assets

As a last example, let's read an XML file from Assets folder.

Place an XML file in Assets folder as below :

Now, let's create a label and a textButton as below :

var myLabel = new SMF.UI.Label({
	left : "12%",
	top : "25%",
	height : "20%",
	text : "",
	multipleLine : true,
	backgroundTransparent : false
});
var myXmlButton = new SMF.UI.TextButton({
	left : "12%",
	top : "60%",
	height : "10%",
	text : "Read xml",
	onPressed : function (e) {
		var streamReader = new SMF.IO.FileStream("assets://", "myXmlFile.xml", SMF.IO.StreamType.READ);
		myLabel.text = streamReader.readToEnd();
	}
});
page1.add(myLabel);
page1.add(myXmlButton);

When pressed to textButton, XML will be read and written on the label :