FLARManager + Use In MXML

25 views
Skip to first unread message

dk

unread,
Dec 15, 2009, 11:35:06 PM12/15/09
to FLARToolKit userz
I am trying to use a actionscript file that controls the webcam in my
MXML file, i have attached the code for both files, but when i run the
project i get the following error:

I also tried putting the code in the actual MXML file inside script
tags, but couldnt get to work either.

TypeError: Error #1009: Cannot access a property or method of a null
object reference.
at components::flashmarkers/onFlarManagerInited()[/Users/
Documents/Flex Builder 3/FlashCard_Dev/src/components/flashmarkers.as:
67]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.transmote.flar::FLARManager/checkForInitComplete()[/
ActionScript/com/transmote/flar/FLARManager.as:1165]
at com.transmote.flar::FLARManager/onPatternsLoaded()[/
ActionScript/com/transmote/flar/FLARManager.as:1129]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.transmote.flar.pattern::FLARPatternLoader/
checkForLoadCompletion()[/ActionScript/com/transmote/flar/pattern/
FLARPatternLoader.as:203]
at com.transmote.flar.pattern::FLARPatternLoader/onPatternLoaded
()[/ActionScript/com/transmote/flar/pattern/FLARPatternLoader.as:195]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

Very new at this so not really sure what to do.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
width="800" height="600"
xmlns:camera="components.*">

<camera:flashmarkers />

</mx:Application>


package components
{

import com.transmote.flar.FLARManager;
import com.transmote.flar.marker.FLARMarker;
import com.transmote.flar.marker.FLARMarkerEvent;
import com.transmote.flar.utils.geom.FLARPVGeomUtils;

import flash.display.Sprite;
import flash.events.Event;

import org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.LazyRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

[SWF(width='640', height='480', backgroundColor='#000000',
frameRate='40')]

public class flashmarkers extends Sprite
{

private var flarManager:FLARManager;

private var scene3D:Scene3D;
private var camera3D:FLARCamera3D;
private var viewport3D:Viewport3D;
private var renderEngine:LazyRenderEngine;
private var pointLight3D:PointLight3D;

private var activeMarker:FLARMarker;
private var modelContainer:DisplayObject3D;

import org.papervision3d.view.stats.StatsView;

public function flashmarkers()
{
// pass the path to the
FLARManager xml config file into the FLARManager constructor.
// FLARManager creates and uses a
FLARCameraSource by default.
// the image from the first detected camera
will be used for marker detection.
this.flarManager = new FLARManager
("flarConfig.xml");

// add FLARManager.flarSource to the display
list to display the video capture.
this.addChild(Sprite
(this.flarManager.flarSource));

// begin listening for FLARMarkerEvents.
this.flarManager.addEventListener
(FLARMarkerEvent.MARKER_ADDED, this.onMarkerAdded);
this.flarManager.addEventListener
(FLARMarkerEvent.MARKER_UPDATED, this.onMarkerUpdated);
this.flarManager.addEventListener
(FLARMarkerEvent.MARKER_REMOVED, this.onMarkerRemoved);

// wait for FLARManager to initialize before
setting up Papervision3D environment.
this.flarManager.addEventListener(Event.INIT,
this.onFlarManagerInited);
}

private function onFlarManagerInited (evt:Event) :void
{
this.flarManager.removeEventListener
(Event.INIT, this.onFlarManagerInited);

this.scene3D = new Scene3D();

// initialize FLARCamera3D with parsed camera
parameters.
this.camera3D = new FLARCamera3D
(this.flarManager.cameraParams);

this.camera3D.z = 100;

this.viewport3D = new Viewport3D
(this.stage.stageWidth, this.stage.stageHeight);
this.addChild(this.viewport3D);

this.renderEngine = new LazyRenderEngine
(this.scene3D, this.camera3D, this.viewport3D);

this.pointLight3D = new PointLight3D();
this.pointLight3D.x = 1000;
this.pointLight3D.y = 1000;
this.pointLight3D.z = -1000;

// load the model.
// (this model has to be scaled and rotated to
fit the marker; every model is different.)

var model1:DAE = new DAE(true, "model1",
true);
model1.load("../images/HockeyPlayer.dae");
//model1.rotationX = 90;
model1.rotationZ = -90;
model1.scale = 0.50;
model1.rotationY = -90;

// load the model.
// (this model has to be scaled and rotated to
fit the marker; every model is different.)

var model2:DAE = new DAE(true, "model2",
true);
model2.load("../images/SoccerPlayer.dae");
//model2.rotationX = 90;
model2.rotationZ = -90;
model2.scale = 0.50;
model2.rotationY = -90;

// create a container for the model, that
will accept matrix transformations.

this.modelContainer = new DisplayObject3D();

this.modelContainer.addChild(model1);
this.modelContainer.visible = true;
this.modelContainer.children.model1.visible =
false;

this.modelContainer.addChild(model2);
this.modelContainer.children.model2.visible =
false;
this.scene3D.addChild(this.modelContainer);

var stats:StatsView = new StatsView
(renderEngine);

addChild(stats);
//-------------------------------------------------------------------------
---------
this.addEventListener(Event.ENTER_FRAME,
this.onEnterFrame);
}

private function onMarkerAdded
(evt:FLARMarkerEvent) :void {

trace("["+evt.marker.patternId+"] added");
switch(evt.marker.patternId)
{
case 0:
trace("pat 1 recognized");

this.modelContainer.children.model1.visible = true;
break;
case 1:
trace("pat 2 recognized");

this.modelContainer.children.model2.visible = true;
break;

}

this.activeMarker = evt.marker;
}

private function onMarkerUpdated
(evt:FLARMarkerEvent) :void {

trace("["+evt.marker.patternId+"]
updated");

switch(evt.marker.patternId)
{

case 0:
trace("pat 1
updated");
//trace("children
list: "+ this.modelContainer.childrenList());

this.modelContainer.children.model1.visible = true;
break;
case 1:
trace("pat 2
updated");

this.modelContainer.children.model2.visible = true;
break;
}

this.activeMarker = evt.marker;
}

private function onMarkerRemoved
(evt:FLARMarkerEvent) :void {

trace("["+evt.marker.patternId+"]
removed");
switch(evt.marker.patternId)
{

case 0:
trace("pat 1
removed");

this.modelContainer.children.model1.visible = false;
break;
case 1:
trace("pat 1
removed");

this.modelContainer.children.model2.visible = false;
break;

}

this.activeMarker = null;
}

private function onEnterFrame
(evt:Event) :void {

// apply the FLARToolkit
transformation matrix to the Cube.
if (this.activeMarker) {
this.modelContainer.transform =

FLARPVGeomUtils.convertFLARMatrixToPVMatrix
(this .activeMarker.transformMatrix);
}

this.renderEngine.render();
}
}
}

eric socolofsky

unread,
Dec 15, 2009, 11:53:33 PM12/15/09
to flartool...@googlegroups.com
first off, yes, you should have your actionscript within an <mx:script> tag.  something like:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxmllayout="absolute" applicationComplete="onApplicationComplete()" >

    

    <mx:Script>
    <![CDATA[
private function onApplicationComplete () :void {
// start app here
}
]]>
    </mx:Script>

</mx:Application>


i'm not sure what is causing the null ref error in your code, what is line 67 of flashmarkers.as?

dk

unread,
Dec 16, 2009, 10:29:34 AM12/16/09
to FLARToolKit userz
Thanks for the help.

How do i start the app? What code do i need to put in the
onApplicationComplete function?

dk

unread,
Dec 16, 2009, 6:37:09 PM12/16/09
to FLARToolKit userz
i have tried the below code, and the page loads and asks me if can
access webcam, i allow and my webcam light comes on but i dont see
anything on the screen - any ideas?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
width="800" height="600"

applicationComplete="onApplicationComplete()">
<!--xmlns:camera="components.*">-->
<mx:Script>
<![CDATA[

import com.transmote.flar.FLARManager;
import com.transmote.flar.marker.FLARMarker;
import com.transmote.flar.marker.FLARMarkerEvent;
import com.transmote.flar.utils.geom.FLARPVGeomUtils;

import flash.display.Sprite;
import flash.events.Event;

import org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.LazyRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

[SWF(width='640', height='480', backgroundColor='#000000',
frameRate='40')]

private var flarManager:FLARManager;

private var scene3D:Scene3D;
private var camera3D:FLARCamera3D;
private var viewport3D:Viewport3D;
private var renderEngine:LazyRenderEngine;
private var pointLight3D:PointLight3D;

private var activeMarker:FLARMarker;
private var modelContainer:DisplayObject3D;

import org.papervision3d.view.stats.StatsView;

private function onApplicationComplete():void
{


// pass the path to the FLARManager xml config file into the
FLARManager constructor.
// FLARManager creates and uses a FLARCameraSource by default.
// the image from the first detected camera will be used for marker
detection.

this.flarManager = new FLARManager("flarConfig.xml");

this.scene3D = new Scene3D();

this.camera3D.z = 100;

this.modelContainer = new DisplayObject3D();

}

this.activeMarker = evt.marker;
}

trace("["+evt.marker.patternId+"] updated");

switch(evt.marker.patternId)
{

}

this.activeMarker = evt.marker;
}

}

this.activeMarker = null;
}

this.renderEngine.render();
}
]]>
</mx:Script>

</mx:Application>

> ...
>
> read more »

eric socolofsky

unread,
Dec 16, 2009, 7:11:49 PM12/16/09
to flartool...@googlegroups.com
usually when that happens it's because flash player failed to load some external files (e.g. flarConfig.xml, FLARCameraParams.dat, etc) due to missing files or incorrect paths.

dk

unread,
Dec 16, 2009, 7:52:01 PM12/16/09
to FLARToolKit userz
I stepped through the code to see where the problem could be and it
seems like it gets the below error:

TypeError: Error #1034: Type Coercion failed: cannot convert
com.transmote.flar.source::FLARCameraSource@1cd30d79 to
mx.core.IUIComponent.
at mx.core::Container/http://www.adobe.com/2006/flex/mx/
internal::addingChild()[C:\autobuild\galaga\frameworks\projects
\framework\src\mx\core\Container.as:3302]
at mx.core::Container/addChildAt()[C:\autobuild\galaga\frameworks
\projects\framework\src\mx\core\Container.as:2250]
at mx.core::Container/addChild()[C:\autobuild\galaga\frameworks
\projects\framework\src\mx\core\Container.as:2183]
at FlashCard_Dev/onApplicationComplete()[/Users/juliekilby/Documents/
Flex Builder 3/FlashCard_Dev/src/FlashCard_Dev.mxml:50]
at FlashCard_Dev/___FlashCard_Dev_Application1_applicationComplete()[/
Users/juliekilby/Documents/Flex Builder 3/FlashCard_Dev/src/
FlashCard_Dev.mxml:4]


at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()

at mx.core::UIComponent/dispatchEvent()[C:\autobuild\galaga\frameworks
\projects\framework\src\mx\core\UIComponent.as:9408]
at mx.managers::SystemManager/preloader_preloaderDoneHandler()[C:
\autobuild\galaga\frameworks\projects\framework\src\mx\managers
\SystemManager.as:3136]


at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()

at mx.preloaders::Preloader/displayClassCompleteHandler()[C:\autobuild
\galaga\frameworks\projects\framework\src\mx\preloaders\Preloader.as:
435]


at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()

at mx.preloaders::DownloadProgressBar/timerHandler()[C:\autobuild
\galaga\frameworks\projects\framework\src\mx\preloaders
\DownloadProgressBar.as:1451]
at mx.preloaders::DownloadProgressBar/initCompleteHandler()[C:
\autobuild\galaga\frameworks\projects\framework\src\mx\preloaders
\DownloadProgressBar.as:1503]


at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()

at mx.preloaders::Preloader/dispatchAppEndEvent()[C:\autobuild\galaga
\frameworks\projects\framework\src\mx\preloaders\Preloader.as:291]
at mx.preloaders::Preloader/appCreationCompleteHandler()[C:\autobuild
\galaga\frameworks\projects\framework\src\mx\preloaders\Preloader.as:
443]


at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()

at mx.core::UIComponent/dispatchEvent()[C:\autobuild\galaga\frameworks
\projects\framework\src\mx\core\UIComponent.as:9408]
at mx.core::UIComponent/set initialized()[C:\autobuild\galaga
\frameworks\projects\framework\src\mx\core\UIComponent.as:1169]
at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild
\galaga\frameworks\projects\framework\src\mx\managers\LayoutManager.as:
718]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\galaga
\frameworks\projects\framework\src\mx\core\UIComponent.as:8733]
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\galaga
\frameworks\projects\framework\src\mx\core\UIComponent.as:8673]

at this line of code - this.addChild(Sprite
(this.flarManager.flarSource));
when i use the code in an AS file in separate project i have this line
it, and removed it when i put it in the MXML file, could this be part
of the problem and if so how can i fix.

public class flashmarkers extends Sprite

> ...
>
> read more »

eric socolofsky

unread,
Dec 17, 2009, 12:27:34 AM12/17/09
to flartool...@googlegroups.com
aha. in that case, try rawChildren.addChild(flarSource) instead of just addChild(flarSource).

Blake Callens

unread,
Dec 17, 2009, 2:29:49 PM12/17/09
to FLARToolKit userz
You could try ARtisan, which is built on MXML component structure.
http://onezerothrice.com/artisan

> ...
>
> read more »

dk

unread,
Dec 18, 2009, 8:41:34 PM12/18/09
to FLARToolKit userz
rawChildren.addChild worked - thank you

Do you know how i can control where the camera is located on the page,
or can i have it inserted into a panel control and then have more
control over the location?

Thanks for the help

> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages