<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    initialize="updateCar()" enterFrame="onEnterFrame()" viewSourceURL="srcview/index.html">
    
    <mx:Style source="styles.css" />
    
    <mx:Script>
        <![CDATA[
            
            private var car:Car = new Car( new Point(100,200), -Math.PI/2);
            
            private function onEnterFrame():void
            {
                car.move();
                
                if(car.position.x < 0 || car.position.x > canvas.width
                    || car.position.y < 0 || car.position.y > canvas.height)
                    car.position = new Point(canvas.width/2, canvas.height/2);
                    
                    
                car.draw(canvas.graphics);
            }
            
            private function updateCar():void
            {
                car.speed = hs_speed.value;
                car.steering = hs_steering.value * -1;
            }
        ]]>
    </mx:Script>



    <!-- Controls -->    
    <mx:Label x="10" y="10" text="Speed:"/>
    <mx:HSlider id="hs_speed" x="74" y="10" allowTrackClick="true" minimum="-10" maximum="10" snapInterval="0.1" liveDragging="true" value="2" change="{updateCar();}"/>
    
    <mx:Label x="10" y="36" text="Steering:"/>
    <mx:HSlider id="hs_steering" x="74" y="42" allowTrackClick="true" minimum="-1.2" maximum="1.2" snapInterval="0.1" value="-0.4" liveDragging="true" change="{updateCar();}"/>
    
    
    <!-- Canvas to draw the car on -->
    <mx:UIComponent id="canvas" width="100%" height="100%"/>
    
    
    
    
    <mx:ApplicationControlBar dock="true" verticalAlign="top">    
        <mx:Label text="Driving" styleName="headderText"/>        
        <mx:Spacer width="-20" />        
        <mx:Label text="Simulator" styleName="headderTextBlue"/>
        <mx:Label text="Demo" styleName="headderText"/>
        <mx:Script>
            <![CDATA[ import flash.net.navigateToURL; ]]>
        </mx:Script>
        <mx:Spacer width="100%" />
        <mx:LinkButton label="created by Tony Fendall" color="#FFFFFF" click="{navigateToURL( new URLRequest('http://www.munkiihouse.com'))}" />
    </mx:ApplicationControlBar>
</mx:Application>