The emergence of prosumers, as new players in the distribution networks, provides the opportunity to manage distributed energy resources (DERs) at a local level. However, designing an appropriate framework that empowers prosumers to manage their resources and trade energy with each other is a challenging task. This paper proposes a framework for joint scheduling and power trading of a community of prosumers in a transactive energy market (TEM). Prosumers perform day-ahead energy management to schedule their flexible energy resources to reduce their energy expenses. In the scheduling step, each prosumer indicates the expected surplus/deficit energy, which needs to be traded in different markets as well as the flexibility which can be provided in response to grid operator's requests. Then, in intra-day markets, prosumers can trade energy with either their neighbors in a peer-to-peer (P2P) market or the grid. Also, prosumers can participate in an event-driven flexibility market to respond to the requested flexibility by the grid operator. A distributed price-directed market clearing mechanism is presented, which ensures the privacy of prosumers and the market scalability. Simulation results show that energy trading in the community reduces prosumers energy costs, while the grid operator can utilize prosumers' flexibility for managing grid constraints.