Finally got the answer...
Context context = CCDirector.sharedDirector().getActivity().getApplicationContext();
InputStream is = context.getAssets().open("abc.txt");
Question
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
???
Solution
Finally got the answer...
Context context = CCDirector.sharedDirector().getActivity().getApplicationContext();
InputStream is = context.getAssets().open("abc.txt");
OTHER TIPS
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());
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.