Skip to main content
June 14, 2012
Question

Dynamically create movieclips

  • June 14, 2012
  • 1 reply
  • 905 views

I want to be able to dynamically create movieclips in flash based on a midi file.

So I converted the midi file to an .xml file first. I traced the number of events going on and the time of when an event starts or ends.

So to keep track of those times, I put them in an array.(keytimer)

The timer goes up 1microsecond at a time, for as long as the song is; in this case 190080 microseconds.

The thing I want is when the timer equals a number in this array(keytimer), and only when the attribute is 'NoteOn', then it should create a movieclip.

I tried doing it like this; but he doesnt recognise the array:

if (current==keytimer) {

trace("yes");

}

Any help is more than welcome

Flash file:

var xmlLoader:URLLoader = new URLLoader();

xmlLoader.addEventListener(Event.COMPLETE, showXML);

xmlLoader.load(new URLRequest("for_elise_by_beethoven.xml"));

function showXML(e:Event):void {

XML.ignoreWhitespace=true;

var songs:XML=new XML(e.target.data);

trace(songs.Track.Event.length());

var i:Number;

var keytimer:Array = new Array();

for (i=0; i < songs.Track.Event.length(); i++) {

keytimer =(" Time of the key: "+ songs.Track.Event.Absolute.text());

if (current==keytimer) {

trace("yes");

}

//trace(keytimer);

//trace(" NoteOn: "+ songs.Track.Event.NoteOn.@Note);

//trace(" NoteOff: "+ songs.Track.Event.NoteOff.@Note);

//trace(" ");

}

var myTimer:Timer=new Timer(1,190000);

myTimer.addEventListener(TimerEvent.TIMER,doStuff);

var current:Number=0;

myTimer.start();

function doStuff(event:TimerEvent):void {

current++;

trace("current: "+ current);

trace("keytimer: "+ keytimer);

//trace("keytimer: "+ keytimer);

/*if (current==keytimer) {

trace("yes");

}*/

}

}

The current xml file: (name: for_elise_by_beethoven.xml)

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE MIDIFile PUBLIC

  "-//Recordare//DTD MusicXML 0.9 MIDI//EN"

  "http://www.musicxml.org/dtds/midixml.dtd">

<MIDIFile>

<Format>1</Format>

<TrackCount>4</TrackCount>

<TicksPerBeat>960</TicksPerBeat>

<TimestampType>Absolute</TimestampType>

<Track Number="0">

  <Event>

    <Absolute>0</Absolute>

    <SequencerSpecific>05 0f 12 00 00 7f 7f 00</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <SequencerSpecific>05 0f 1c 32 30 30 35 2e 31 32 2e 30 32</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <TrackName>Track 0</TrackName>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <SetTempo Value="857143"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <EndOfTrack/>

  </Event>

</Track>

<Track Number="1">

  <Event>

    <Absolute>0</Absolute>

    <ProgramChange Channel="1" Number="0"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <SequencerSpecific>05 0f 09 40 48</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <CopyrightNotice>2006 by forelise.com</CopyrightNotice>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <InstrumentName>Piano</InstrumentName>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <TrackName>Für Elise</TrackName>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <SequencerSpecific>05 0f 06 47 65 6e 65 72 61 6c 20 4d 49 44 49</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <TimeSignature Numerator="3" LogDenominator="3" MIDIClocksPerMetronomeClick="12" ThirtySecondsPer24Clocks="8"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <MIDIChannelPrefix Value="00"/>

  </Event>

  <Event>

    <Absolute>960</Absolute>

    <NoteOn Channel="1" Note="76" Velocity="71"/>

  </Event>

  <Event>

    <Absolute>1200</Absolute>

    <NoteOff Channel="1" Note="76" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>1200</Absolute>

    <NoteOn Channel="1" Note="75" Velocity="38"/>

  </Event>

  <Event>

    <Absolute>1440</Absolute>

    <NoteOff Channel="1" Note="75" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>1440</Absolute>

    <NoteOn Channel="1" Note="76" Velocity="57"/>

  </Event>

  <Event>

    <Absolute>1680</Absolute>

    <NoteOff Channel="1" Note="76" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>1680</Absolute>

    <NoteOn Channel="1" Note="75" Velocity="70"/>

  </Event>

  <Event>

    <Absolute>1920</Absolute>

    <NoteOff Channel="1" Note="75" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>1920</Absolute>

    <NoteOn Channel="1" Note="76" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>2160</Absolute>

    <NoteOff Channel="1" Note="76" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>2160</Absolute>

    <NoteOn Channel="1" Note="71" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>2400</Absolute>

    <NoteOff Channel="1" Note="71" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>2400</Absolute>

    <NoteOn Channel="1" Note="74" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>2640</Absolute>

    <NoteOff Channel="1" Note="74" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>2640</Absolute>

    <NoteOn Channel="1" Note="72" Velocity="83"/>

  </Event>

  <Event>

    <Absolute>2880</Absolute>

    <NoteOff Channel="1" Note="72" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>2880</Absolute>

    <NoteOn Channel="1" Note="69" Velocity="89"/>

  </Event>

  <Event>

    <Absolute>2880</Absolute>

    <SequencerSpecific>05 0f 0f 02</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>2880</Absolute>

    <NoteOn Channel="1" Note="45" Velocity="64"/>

  </Event>

  <Event>

    <Absolute>3120</Absolute>

    <NoteOff Channel="1" Note="45" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>3120</Absolute>

    <NoteOn Channel="1" Note="52" Velocity="64"/>

  </Event>

  <Event>

    <Absolute>3360</Absolute>

    <NoteOff Channel="1" Note="52" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>3360</Absolute>

    <NoteOn Channel="1" Note="57" Velocity="70"/>

  </Event>

  <Event>

    <Absolute>3600</Absolute>

    <NoteOff Channel="1" Note="69" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>3600</Absolute>

    <NoteOff Channel="1" Note="57" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>3600</Absolute>

    <NoteOn Channel="1" Note="60" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>3840</Absolute>

    <NoteOff Channel="1" Note="60" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>3840</Absolute>

    <NoteOn Channel="1" Note="64" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>4080</Absolute>

    <NoteOff Channel="1" Note="64" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>4080</Absolute>

    <NoteOn Channel="1" Note="69" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>4320</Absolute>

    <NoteOff Channel="1" Note="69" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>4320</Absolute>

    <NoteOn Channel="1" Note="71" Velocity="83"/>

  </Event>

  <Event>

    <Absolute>4320</Absolute>

    <SequencerSpecific>05 0f 0f 02</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>4320</Absolute>

    <NoteOn Channel="1" Note="40" Velocity="64"/>

  </Event>

  <Event>

    <Absolute>4560</Absolute>

    <NoteOff Channel="1" Note="40" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>4560</Absolute>

    <NoteOn Channel="1" Note="52" Velocity="64"/>

  </Event>

  <Event>

    <Absolute>4800</Absolute>

    <NoteOff Channel="1" Note="52" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>4800</Absolute>

    <NoteOn Channel="1" Note="56" Velocity="70"/>

  </Event>

  <Event>

    <Absolute>5040</Absolute>

    <NoteOff Channel="1" Note="71" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>5040</Absolute>

    <NoteOff Channel="1" Note="56" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>5040</Absolute>

    <NoteOn Channel="1" Note="64" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>5280</Absolute>

    <NoteOff Channel="1" Note="64" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>5280</Absolute>

    <NoteOn Channel="1" Note="68" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>5520</Absolute>

    <NoteOff Channel="1" Note="68" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>5520</Absolute>

    <NoteOn Channel="1" Note="71" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>5760</Absolute>

    <NoteOff Channel="1" Note="71" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>5760</Absolute>

    <NoteOn Channel="1" Note="72" Velocity="83"/>

  </Event>

  <Event>

    <Absolute>5760</Absolute>

    <NoteOn Channel="1" Note="45" Velocity="64"/>

  </Event>

  <Event>

    <Absolute>6000</Absolute>

    <NoteOff Channel="1" Note="45" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>6000</Absolute>

    <NoteOn Channel="1" Note="52" Velocity="70"/>

  </Event>

  <Event>

    <Absolute>6240</Absolute>

    <NoteOff Channel="1" Note="52" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>6240</Absolute>

    <NoteOn Channel="1" Note="57" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>6480</Absolute>

    <NoteOff Channel="1" Note="72" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>6480</Absolute>

    <NoteOff Channel="1" Note="57" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>6480</Absolute>

    <NoteOn Channel="1" Note="64" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>6720</Absolute>

    <NoteOff Channel="1" Note="64" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>6720</Absolute>

    <NoteOn Channel="1" Note="76" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>6960</Absolute>

    <NoteOff Channel="1" Note="76" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>6960</Absolute>

    <NoteOn Channel="1" Note="75" Velocity="64"/>

  </Event>

  <Event>

    <Absolute>7200</Absolute>

    <NoteOff Channel="1" Note="75" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>7200</Absolute>

    <NoteOn Channel="1" Note="76" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>7440</Absolute>

    <NoteOff Channel="1" Note="76" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>7440</Absolute>

    <NoteOn Channel="1" Note="75" Velocity="70"/>

  </Event>

  <Event>

    <Absolute>7680</Absolute>

    <NoteOff Channel="1" Note="75" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>7680</Absolute>

    <NoteOn Channel="1" Note="76" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>7920</Absolute>

    <NoteOff Channel="1" Note="76" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>7920</Absolute>

    <NoteOn Channel="1" Note="71" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>8160</Absolute>

    <NoteOff Channel="1" Note="71" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>8160</Absolute>

    <NoteOn Channel="1" Note="74" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>8400</Absolute>

    <NoteOff Channel="1" Note="74" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>8400</Absolute>

    <NoteOn Channel="1" Note="72" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>8640</Absolute>

    <NoteOff Channel="1" Note="72" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>8640</Absolute>

    <NoteOn Channel="1" Note="69" Velocity="83"/>

  </Event>

  <Event>

    <Absolute>8640</Absolute>

    <SequencerSpecific>05 0f 0f 02</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>8640</Absolute>

    <NoteOn Channel="1" Note="45" Velocity="57"/>

  </Event>

  <Event>

    <Absolute>8880</Absolute>

    <NoteOff Channel="1" Note="45" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>8880</Absolute>

    <NoteOn Channel="1" Note="52" Velocity="64"/>

  </Event>

  <Event>

    <Absolute>9120</Absolute>

    <NoteOff Channel="1" Note="52" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>9120</Absolute>

    <NoteOn Channel="1" Note="57" Velocity="70"/>

  </Event>

  <Event>

    <Absolute>9360</Absolute>

    <NoteOff Channel="1" Note="69" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>9360</Absolute>

    <NoteOff Channel="1" Note="57" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>9360</Absolute>

    <NoteOn Channel="1" Note="60" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>9600</Absolute>

    <NoteOff Channel="1" Note="60" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>9600</Absolute>

    <NoteOn Channel="1" Note="64" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>9840</Absolute>

    <NoteOff Channel="1" Note="64" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>9840</Absolute>

    <NoteOn Channel="1" Note="69" Velocity="76"/>

  </Event>

  <Event>

    <Absolute>10080</Absolute>

    <NoteOff Channel="1" Note="69" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>10080</Absolute>

    <NoteOn Channel="1" Note="71" Velocity="83"/>

  </Event>







          ...ETC...





  <Event>

    <Absolute>185040</Absolute>

    <NoteOff Channel="1" Note="56" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>185040</Absolute>

    <NoteOn Channel="1" Note="64" Velocity="51"/>

  </Event>

  <Event>

    <Absolute>185280</Absolute>

    <NoteOff Channel="1" Note="64" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>185280</Absolute>

    <NoteOn Channel="1" Note="72" Velocity="51"/>

  </Event>

  <Event>

    <Absolute>185520</Absolute>

    <NoteOff Channel="1" Note="72" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>185520</Absolute>

    <NoteOn Channel="1" Note="71" Velocity="51"/>

  </Event>

  <Event>

    <Absolute>185733</Absolute>

    <ControlChange Channel="1" Control="64" Value="127"/>

  </Event>

  <Event>

    <Absolute>185760</Absolute>

    <NoteOff Channel="1" Note="71" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>185760</Absolute>

    <SequencerSpecific>05 0f 0e</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>185760</Absolute>

    <NoteOn Channel="1" Note="60" Velocity="45"/>

  </Event>

  <Event>

    <Absolute>185760</Absolute>

    <NoteOn Channel="1" Note="69" Velocity="45"/>

  </Event>

  <Event>

    <Absolute>185760</Absolute>

    <NoteOn Channel="1" Note="45" Velocity="45"/>

  </Event>

  <Event>

    <Absolute>185760</Absolute>

    <NoteOn Channel="1" Note="33" Velocity="45"/>

  </Event>

  <Event>

    <Absolute>187200</Absolute>

    <NoteOff Channel="1" Note="45" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>187200</Absolute>

    <NoteOff Channel="1" Note="33" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>187200</Absolute>

    <NoteOff Channel="1" Note="60" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>187200</Absolute>

    <NoteOff Channel="1" Note="69" Velocity="0"/>

  </Event>

  <Event>

    <Absolute>190048</Absolute>

    <ControlChange Channel="1" Control="64" Value="0"/>

  </Event>

  <Event>

    <Absolute>190080</Absolute>

    <SequencerSpecific>05 0f 0a</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>190080</Absolute>

    <EndOfTrack/>

  </Event>

</Track>

<Track Number="2">

  <Event>

    <Absolute>0</Absolute>

    <SequencerSpecific>05 0f 09 00 40</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <SequencerSpecific>05 0f 06 47 65 6e 65 72 61 6c 20 4d 49 44 49</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <TrackName>http://www.forelise.com/</TrackName>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <TimeSignature Numerator="3" LogDenominator="3" MIDIClocksPerMetronomeClick="12" ThirtySecondsPer24Clocks="8"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <ProgramChange Channel="2" Number="0"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <MIDIChannelPrefix Value="01"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <EndOfTrack/>

  </Event>

</Track>

<Track Number="3">

  <Event>

    <Absolute>0</Absolute>

    <SequencerSpecific>05 0f 09 00 40</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <SequencerSpecific>05 0f 06 47 65 6e 65 72 61 6c 20 4d 49 44 49</SequencerSpecific>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <TrackName>Composed by Ludwig van Beethoven</TrackName>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <TimeSignature Numerator="3" LogDenominator="3" MIDIClocksPerMetronomeClick="12" ThirtySecondsPer24Clocks="8"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <ProgramChange Channel="3" Number="0"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <MIDIChannelPrefix Value="02"/>

  </Event>

  <Event>

    <Absolute>0</Absolute>

    <EndOfTrack/>

  </Event>

</Track>

</MIDIFile>

This topic has been closed for replies.

1 reply

esdebon
Inspiring
June 14, 2012

.

.

.

var current:int=0;

myTimer.start();

function doStuff(event:TimerEvent):void {

current++;

trace("current: "+ current);

trace("keytimer: "+ keytimer);

//trace("keytimer: "+ keytimer);

if (current==int(keytimer[i)]) {

trace("yes");

}

...

June 15, 2012

He still outputs:

current: 1

keytimer: undefined

current: 2

keytimer: undefined

current: 3

keytimer: undefined

current: 4

keytimer: undefined

...etc

esdebon
Inspiring
June 15, 2012

try

trace(songs.Track.Event.Absolute);

keytimer =int(songs.Track.Event.Absolute);

if (current==keytimer) {

      trace("yes");

}