Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

problem with as3 linking with xml

New Here ,
Jul 15, 2011 Jul 15, 2011

Hi

Please Please help me with this.

I am getting

"Error #1069: Property data not found on flash.display.Sprite and there is no default value.

at flashhaupt01_fla::GalleryData01_1/imagepress()" error in as3.

I am trying to get the url from xml into as3, but not getting how to do it. please help me.

I need to demo this within 1 hour

here is my code

var xmlReq:URLRequest = new URLRequest("XML/ImagesData01.xml"); // rename to your file!!!

var xmlLoader:URLLoader = new URLLoader();

//xmlLoader.addEventListener(Event.COMPLETE, xmlLoader); // event listener b4 load!!!

xmlLoader.load(xmlReq);

var myXML:XML;

var headLoader:Loader;

function imagepress(e:MouseEvent):void  {

//navigateToURL(new URLRequest("XML/ImagesData01.xml"));

myXML = new XML(e.target.data);

for (var i:int = 0; i < myXML.children().length(); i++)

    {

        headLoader = new Loader();

        headLoader.load(new URLRequest(String(myXML.data.@image)));

       // headLoader.x = startX;

        //headLoader.y = 0;

        headLoader.name = String(i);

        addChild(headLoader);

}

please help me

TOPICS
ActionScript
828
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 15, 2011 Jul 15, 2011

Assuming imagepress is called when you click on some image, the target of the event (e) could be any object within the object that has the event listener assigned to it.  There error seems to be indicating that you are expecting to extract a "data" property from a Sprite object that has been clicked.

Where is the data you seek?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2011 Jul 15, 2011

Thanks for replying,

Actually i am a fresher and very new to AS3 and xml.

Here is my AS code

When i click on any image it should go to a url i have mentioned in the xml file

stop();

import fl.transitions.Tween;

import fl.transitions.easing.*;

import flash.display.Sprite;

import flash.events.MouseEvent;

import flash.display.*;

import flash.events.Event;

import flash.display.Shape;

import flash.display.MovieClip;

import flash.display.Bitmap;

import flash.display.BitmapData;

import flash.display.DisplayObject;

import flash.display.Loader;

import flash.events.Event;

import flash.geom.Point;

import flash.net.URLRequest;

import flash.net.URLLoader;

import flash.geom.ColorTransform;

import flash.net.navigateToURL;

import org.papervision3d.scenes.*;

import org.papervision3d.cameras.*;

import org.papervision3d.objects.*;

import org.papervision3d.materials.*;

import org.papervision3d.materials.BitmapMaterial;

var container:Sprite = new Sprite();

container.x = 0;

container.y = 0;

addChild(container);

var scene:Scene3D = new MovieScene3D(container);

var cam:Camera3D = new Camera3D();

var new_zoom:Number;

cam.zoom = 6;

var planedictionary:Dictionary = new Dictionary();

var imageplane:Plane = new Plane();

imageplane.visible = false;

cam.target = imageplane;

var maxRows:Number = 3;

var yaxis:Number = 0;

var anglenumber:Number = 100;

var image = new Array();

var urllink = new Array();

var urltarget:Array = new Array();

var planes = new Array();

var i:Number;

var max:Number;

var li:Number = 0;

var center:Number = 6.4;

var zoom:Number = 10;

var cameramove:Boolean = true;

var camerapositionX:Number;

var camerapositionY:Number;

var showimage:Boolean = true;

var imageholder;

var xposition:Number;

var yposition:Number;

var zoomdistance:Number = 12;

var XML_Load:XML = new XML();

var loader:URLLoader = new URLLoader();

loader.load(new URLRequest("XML/ImagesData01.xml"));

loader.addEventListener(Event.COMPLETE, imagecontainer);

function imagecontainer(e:Event):void  {

XML_Load = XML(e.target.data);

max = XML_Load.data.length();

var displayimage:Number = Math.ceil(max/3);

var anglenumberMath:Number = ((Math.PI*2) * maxRows) / max;

for(i = 0; i < max; i++) {

image.push(XML_Load.data.@imagepath.toString());

urllink.push(XML_Load.data.@url.toString());

urltarget.push(XML_Load.data.@target.toString());

var bfm:BitmapFileMaterial = new BitmapFileMaterial("IMAGES/" + XML_Load.data.@imagepath.toString());

bfm.oneSide = true;

bfm.smooth = true;

var plane:Plane = new Plane(bfm, 140, 105, 2, 2);

scene.addChild(plane);

planes.push(plane);

var planeMC:Sprite = plane.container;

planeMC.name = "" + i;

        planedictionary[planeMC] = plane;

planeMC.buttonMode = true;

planeMC.addEventListener(MouseEvent.ROLL_OVER, imagerollover);

planeMC.addEventListener(MouseEvent.ROLL_OUT, imagerollout);

planeMC.addEventListener(MouseEvent.CLICK, imagepress);

camerapositionX = ((150 * displayimage) - 150) * 0.5;

camerapositionY = ((115 * maxRows) - 115) * 0.5;

plane.x = li * 150 - camerapositionX;

li++;

plane.y = yaxis - camerapositionY;

if((i+1) % displayimage == 0) {

li = 0;

yaxis += 115;

}

}

};

function imagerollover(e:MouseEvent) {

var imagesprite:Sprite = e.target as Sprite;

if(showimage == true) {

}

};

function imagerollout(e:MouseEvent) {

var imagesprite:Sprite = e.target as Sprite;

if(showimage == true) {

}

};

function imagepress(e:MouseEvent):void  {

var imagesprite:Sprite = e.target as Sprite;

if(showimage == true) {

showimage = false;

for each (var key1:Plane in planedictionary) {

        if (key1.container != imagesprite) {

var tween01:Tween = new Tween(key1.container, 'alpha', Strong.easeOut, 1, 0.5, 0.8, true);

key1.container.buttonMode = false;

}

}

imageholder = imagesprite.name;

xposition = planes[imagesprite.name].x;

yposition = planes[imagesprite.name].y;

planes[imagesprite.name].x = 0;

planes[imagesprite.name].y = 0;

planes[imagesprite.name].z = -175;

planes[imagesprite.name].scaleX = 2.0;

planes[imagesprite.name].scaleY = 2.0;

}

else {

if(planes[imagesprite.name] == planes[imageholder]) {

planes[imageholder].scaleX = 1.0;

planes[imageholder].scaleY = 1.0;

planes[imageholder].x = xposition;

planes[imageholder].y = yposition;

planes[imageholder].z = 0;

for each (var key2:Plane in planedictionary) {

        var tween04:Tween = new Tween(key2.container, 'alpha', Strong.easeOut, 0.5, 1, 0.8, true);

key2.container.buttonMode = true;

}

showimage = true;

}

}

};

stage.addEventListener(MouseEvent.MOUSE_WHEEL, CameraZoom);

function CameraZoom(e:MouseEvent) {

var newzoom:Number = zoomdistance + e.delta/5;

if(newzoom < 3) {

newzoom = 3

}

if(newzoom > 18) {

newzoom = 18

}

zoomdistance = newzoom;

};

addEventListener(Event.ENTER_FRAME, render);

function render(e:Event):void {

cam.zoom += (zoomdistance - cam.zoom)/5;

if(cameramove == true) {

cam.x += (((stage.mouseX-(stage.stageWidth * 0.5))*2)-cam.x) * 0.05;

cam.y += (((stage.mouseY-(stage.stageHeight * 0.5))*2)-cam.y) * 0.05;

}

scene.renderCamera(cam);

};

XML Code

<?xml version="1.0" encoding="utf-8"?>

<imagedata>

   <data imagepath="Image01.jpg" url="#" target="_blank" />

   <data imagepath="Image02.jpg" url="#" target="_blank" />

   <data imagepath="Image01.jpg" url="#" target="_blank" />

   <data imagepath="Image02.jpg" url="#" target="_blank" />

   <data imagepath="Image01.jpg" url="#" target="_blank" />

   <data imagepath="Image02.jpg" url="#" target="_blank" />

   <data imagepath="Image01.jpg" url="#" target="_blank" />

   <data imagepath="Image02.jpg" url="#" target="_blank" />

   <data imagepath="Image01.jpg" url="#" target="_blank" />

</imagedata>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 15, 2011 Jul 15, 2011

I have some chores I need to get done, so here's what I'll leave you with.  It appears you are assigning the CLICK event listener to a Sprite object declared as planeMC.  What I sugest is that you declare it as a MovieClip instead so that you can dynamically assign it a reference number ( i ) as a property, let's say you name it "num".  That way, later on in your imagepress function you can use  e.currentTarget.num to identify which url from the urllink array you need to use.... here's a couple snips...

var planeMC:MovieClip = plane.container;   // your current line

planeMC.num = i;

function imagepress(e:MouseEvent):void  {  // your code from earlier

    navigateToURL(new URLRequest(urllink[e.currentTarget.num]));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2011 Jul 15, 2011

Hi, Ned Murphy,

Request you to help me in this .. please..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2011 Jul 15, 2011

I have chnaged it but not sure whether i did it properly or not.

var planeMC:MovieClip = plane.container;

planeMC.num = i;

//var planeMC:Sprite = plane.container;

planeMC.name = "" + i;

        planedictionary[planeMC] = plane;

planeMC.buttonMode = true;

planeMC.addEventListener(MouseEvent.ROLL_OVER, imagerollover);

planeMC.addEventListener(MouseEvent.ROLL_OUT, imagerollout);

planeMC.addEventListener(MouseEvent.CLICK, imagepress);

camerapositionX = ((150 * displayimage) - 150) * 0.5;

camerapositionY = ((115 * maxRows) - 115) * 0.5;

plane.x = li * 150 - camerapositionX;

li++;

plane.y = yaxis - camerapositionY;

if((i+1) % displayimage == 0) {

li = 0;

yaxis += 115;

}

}

};

function imagerollover(e:MouseEvent) {

var imagesprite:Sprite = e.target as Sprite;

if(showimage == true) {

}

};

function imagerollout(e:MouseEvent) {

var imagesprite:Sprite = e.target as Sprite;

if(showimage == true) {

}

};

function imagepress(e:MouseEvent):void  {

navigateToURL(new URLRequest(urllink[e.currentTarget.num]));

var imagesprite:Sprite = e.target as Sprite;

if(showimage == true) {

showimage = false;

for each (var key1:Plane in planedictionary) {

        if (key1.container != imagesprite) {

var tween01:Tween = new Tween(key1.container, 'alpha', Strong.easeOut, 1, 0.5, 0.8, true);

key1.container.buttonMode = false;

}

}

imageholder = imagesprite.name;

xposition = planes[imagesprite.name].x;

yposition = planes[imagesprite.name].y;

planes[imagesprite.name].x = 0;

planes[imagesprite.name].y = 0;

planes[imagesprite.name].z = -175;

planes[imagesprite.name].scaleX = 2.0;

planes[imagesprite.name].scaleY = 2.0;

}

else {

if(planes[imagesprite.name] == planes[imageholder]) {

planes[imageholder].scaleX = 1.0;

planes[imageholder].scaleY = 1.0;

planes[imageholder].x = xposition;

planes[imageholder].y = yposition;

planes[imageholder].z = 0;

for each (var key2:Plane in planedictionary) {

        var tween04:Tween = new Tween(key2.container, 'alpha', Strong.easeOut, 0.5, 1, 0.8, true);

key2.container.buttonMode = true;

}

showimage = true;

}

}

}

Getting error   " Symbol 'GalleryData01', Layer 'Actions01', Frame 1, Line 92 1118: Implicit coercion of a value with static type flash.display:Sprite to a possibly unrelated type flash.display:MovieClip."

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 15, 2011 Jul 15, 2011
LATEST

I have no familiarity with whatever the Plane object is, but whatever it contains that is called 'container' is apparently a Sprite,  so if you have no ability to change that, then you'll need to find another way to get the value of i to associate with the planeMC object.

So if you're stuck with the Sprite, then what you might try is to use its name to carry the value.  I just don't know that there is any valididty in naming an object with a number... I know it won't work if you hard code it that way.  So maybe you name the Sprite something like "pmc_"+String(i), and then later on in your iamgepress function you extract the value of i from the name using String.split("_") to isolate the number as the second element of the array that is returned.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines