If it is still throwing a code for faulty air flow sensor (AFM) after replacing it with a known good one then I would be checking the wiring and plug etc to it (or have you done that?). When the ECU throws that code it is really saying there is a fault with the airflow meter OR its connections.
Check for loose, dirty or poor connections, broken wires, or wires shorting against each other.
Bill G