How to paste a group into a shape so that contents warps accordingly?

Hi. I need help accomplishing something which I assume is pretty basic in Illustrator, but I can't seem to find any tutorial on the web on how to do it.

I made a tall and narrow rectangular shape. Lets just say 40 pixels wide by 800 pixels high. I gave it no stroke, but gave it a red fill. I copied this rectangle six times and aligned them all adjacent to one another, side by side. I gave each of the other six tall and narrow rectangles different fill colors: orange, yellow, green, blue and purple. Then I grouped all seven rectangles together resulting in a rainbow colored rectangle 280 pixels wide and 800 pixels high.

On a separate layer I used the pen tool to create a wavy-like shape, curving, zigging and zagging so that the shape is of varying widths and extends to 800 pixels high from top to bottom. I guess the shape resembles a long winding water-slide at a water theme park, or possibly a winding pillar of smoke coming out of a chimney. I hope you get the picture.

Now, what I want to do is to take that rainbow colored group and somehow insert it into that wavy winding shape. By this I don't mean like a clipping mask, but rather I'm expecting the group of rainbow-colored rectangles to warp and distort itself in reference to the curves and varying widths of the wavy shape in which it is nested.

One way you can make it is, create a pattern brush from the colored rectangle. Then draw a straight line and apply the pattern. Create your shape with the pen tool (as you said). Put the shape on top of the pattern. Select both, then Object > Envelope Distort > Make With Top Object. Then just adjust the anchors as needed. The shape (displayed in black) has to be precise, which means the anchors that run at the top and bottoms should correspond (eg, 8 at the top and 8 at the bottom).

The other way is - very similar - but instead of creating the shape first with the pen tool, just convert the straight pattern into a mesh (Object > Envelope Distort > Make with Mesh. This would be more precise because you can specify the number H/V points on the mesh. Then just twist, twirl, rotate, etc the anchor points of the mesh, until it twirls the way you like it.

thanks for the reply. i tried the 2nd method you suggested - envelope distort > make with mesh. i DID manage to achieve what i wanted with this method, although it was a bit tricky. i was sure there would be some kind of simpler to do this... kind of like envelope distort > make with top object, which seems to reach similar results to what I was looking for but not quite. in fact, even after trying "make with top object" several times with different objects I still couldn't quite figure out what exactly goes on with this envelope distortion.

anyway, thanks for your help! i guess the bottom line is that i managed to get what i want in the end and learned a new tool.