Reputation: 4571
I have a class that extends CCLayer
. I have to get a text file from assets folder. But i couldn't use getAssets()
in this class. How can i use getAssets()
in a class that extends CCLayer
???
Upvotes: 3
Views: 967
Reputation: 4571
Finally got the answer...
Context context = CCDirector.sharedDirector().getActivity().getApplicationContext();
InputStream is = context.getAssets().open("abc.txt");
Upvotes: 3
Reputation: 13541
You have to pass in context to the class to use it. If its your custom class, pass it in the constructor and then hold on it and use it.
Upvotes: 1
Reputation: 243
when you create a method in your class, use:
private void abc (Context context){
context.getAssets();
}
and when you call this method, you must put you context into method:
yourclass.abc(getBaseContext());
Upvotes: 1