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
???
Asked
Active
Viewed 964 times
3

Deepzz
- 4,573
- 1
- 28
- 52
3 Answers
3
Finally got the answer...
Context context = CCDirector.sharedDirector().getActivity().getApplicationContext();
InputStream is = context.getAssets().open("abc.txt");

Deepzz
- 4,573
- 1
- 28
- 52
1
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());

Nguyễn Anh Quế
- 243
- 2
- 10
-
There is no such thing as `getBaseContext()` when i tried to use that, it gave me error :( – Deepzz Jan 18 '13 at 07:33
-
try new yourclass.abc(your_activity.this) or new yourclass.abc(getapplicationcontext()) . you could post detail your class – Nguyễn Anh Quế Jan 18 '13 at 10:31
1
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.

JoxTraex
- 13,423
- 6
- 32
- 45